Gfxprim
Threads by month
- ----- 2026 -----
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- 929 discussions
17 Dec '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 c104daa309d30c1ffd78acb93d1f451f5224d59e (commit)
from d0bede0f6465dc36e6344c977801bbe193df3f06 (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/c104daa309d30c1ffd78acb93d1f451f5224…
commit c104daa309d30c1ffd78acb93d1f451f5224d59e
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Dec 17 19:11:55 2014 +0100
loaders: Fix typos in stubs.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/libs/loaders/GP_GIF.c b/libs/loaders/GP_GIF.c
index 1d6a5fff..097eb322 100644
--- a/libs/loaders/GP_GIF.c
+++ b/libs/loaders/GP_GIF.c
@@ -384,8 +384,8 @@ int GP_MatchGIF(const void GP_UNUSED(*buf))
return -1;
}
-GP_Context *GP_ReadGIF(GP_IO GP_UNUSED(*io),
- GP_ProgressCallback GP_UNUSED(*callback))
+GP_Context *GP_ReadGIFEx(GP_IO GP_UNUSED(*io),
+ GP_ProgressCallback GP_UNUSED(*callback))
{
errno = ENOSYS;
return NULL;
diff --git a/libs/loaders/GP_JPG.c b/libs/loaders/GP_JPG.c
index a0845b3c..386370fd 100644
--- a/libs/loaders/GP_JPG.c
+++ b/libs/loaders/GP_JPG.c
@@ -538,7 +538,7 @@ int GP_WriteJPG(const GP_Context *src, GP_IO *io,
#else
-int GP_ReadJPGEx(GP_IO GP_UNUSED(*io), GP_Context GP_UNUSED(**img,)
+int GP_ReadJPGEx(GP_IO GP_UNUSED(*io), GP_Context GP_UNUSED(**img),
GP_DataStorage GP_UNUSED(*storage),
GP_ProgressCallback GP_UNUSED(*callback))
{
@@ -546,8 +546,8 @@ int GP_ReadJPGEx(GP_IO GP_UNUSED(*io), GP_Context GP_UNUSED(**img,)
return 1;
}
-int GP_WriteJPG(const GP_Context *src, GP_IO *io,
- GP_ProgressCallback *callback)
+int GP_WriteJPG(const GP_Context GP_UNUSED(*src), GP_IO GP_UNUSED(*io),
+ GP_ProgressCallback GP_UNUSED(*callback))
{
errno = ENOSYS;
return 1;
diff --git a/libs/loaders/GP_TIFF.c b/libs/loaders/GP_TIFF.c
index e7dea8dc..806923e9 100644
--- a/libs/loaders/GP_TIFF.c
+++ b/libs/loaders/GP_TIFF.c
@@ -801,7 +801,7 @@ int GP_WriteTIFF(const GP_Context *src, GP_IO *io,
#else
-int GP_ReadTIFFEx(GP_IO GP_UNUSED(*io), GP_Context GP_UNUSED(**img,)
+int GP_ReadTIFFEx(GP_IO GP_UNUSED(*io), GP_Context GP_UNUSED(**img),
GP_DataStorage GP_UNUSED(*storage),
GP_ProgressCallback GP_UNUSED(*callback))
{
-----------------------------------------------------------------------
Summary of changes:
libs/loaders/GP_GIF.c | 4 ++--
libs/loaders/GP_JPG.c | 6 +++---
libs/loaders/GP_TIFF.c | 2 +-
3 files changed, 6 insertions(+), 6 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
23 Nov '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 acd8e4467957c330d8585838a54a054b58f24aca (commit)
from 1176d24e31d0d820628edf8b4d5ba74db4d51cb5 (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/acd8e4467957c330d8585838a54a054b58f2…
commit acd8e4467957c330d8585838a54a054b58f24aca
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Nov 23 09:50:55 2014 +0100
configure: Check for both ft2build.h and freetype2/ft2build.h
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/configure b/configure
index 4208355a..708233fb 100755
--- a/configure
+++ b/configure
@@ -7,18 +7,19 @@ import sys
from optparse import OptionParser
import subprocess
-def header_exists(cfg, filename):
- fpath = cfg['include_path'][0] + '/' + filename
+def header_exists(cfg, *filenames):
+ for filename in filenames:
+ fpath = cfg['include_path'][0] + '/' + filename
- sys.stderr.write("Checking for '%s' ... " % fpath)
+ sys.stderr.write("Checking for '%s' ... " % fpath)
- try:
- st = os.stat(fpath)
- sys.stderr.write("Yesn")
- return True
- except os.error:
- sys.stderr.write("Non")
- return False
+ try:
+ st = os.stat(fpath)
+ sys.stderr.write("Yesn")
+ return True
+ except os.error:
+ sys.stderr.write("Non")
+ return False
def c_try_compile(cfg, code, msg):
sys.stderr.write(msg)
@@ -411,7 +412,8 @@ if __name__ == '__main__':
[header_exists, "aalib.h"], "", "-laa", ["backends"]],
["freetype",
"A high-quality and portable font engine",
- [header_exists, "ft2build.h"], "", "`freetype-config --libs`", ["core"]],
+ [header_exists, "ft2build.h", "freetype2/ft2build.h"],
+ "", "`freetype-config --libs`", ["core"]],
["dl",
"Dynamic linker",
[header_exists, "dlfcn.h"], "", "-ldl", ["core"]],
-----------------------------------------------------------------------
Summary of changes:
configure | 24 +++++++++++++-----------
1 files changed, 13 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
05 Nov '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 7277e9f644891feda13a940bf14b3a6597d19d9f (commit)
This update discarded existing revisions and left the branch pointing at
a previous point in the repository history.
* -- * -- N (1176d24e31d0d820628edf8b4d5ba74db4d51cb5)
O -- O -- O (7277e9f644891feda13a940bf14b3a6597d19d9f)
The removed revisions are not necessarily gone - if another reference
still refers to them they will stay in the repository.
No new revisions were added by this update.
Summary of changes:
gen/bin/cct.py | 298 -----------------------------
gen/include/functions.t | 48 -----
gen/include/gfxprim_config.py | 136 -------------
gen/include/gfxprimconfig.py | 73 -------
gen/include/header.t | 11 -
gen/include/license.t | 10 -
gen/include/pixelsize.py | 39 ----
gen/include/pixeltype.py | 104 ----------
gen/include/source.t | 4 -
genn.mk | 48 -----
include/core/GP_Clamp.h | 7 -
include/core/GP_Convert.gen.h.t | 160 +++++++++-------
include/core/GP_Convert_Scale.gen.h.t | 55 ++++--
include/core/GP_FnPerBpp.gen.h.t | 69 ++++---
include/core/GP_GammaCorrection.gen.h.t | 45 ++++-
include/core/GP_GammaPixel.gen.h.t | 61 ++++--
include/core/GP_GetPutPixel.gen.h.t | 102 +++++++----
include/core/GP_MixPixels.gen.h.t | 96 ++++++---
include/core/GP_MixPixels2.gen.h.t | 54 ++++--
include/core/GP_Pixel.gen.h.t | 90 ++++++---
include/core/GP_WritePixel.gen.h.t | 43 ++++-
include/core/Makefile | 2 +-
include/gfx/GP_HLine.gen.h.t | 40 +++-
include/gfx/GP_VLine.gen.h.t | 40 +++-
include/gfx/Makefile | 2 +-
libs/core/GP_Blit.gen.c.t | 128 ++++++++-----
libs/core/GP_Convert.gen.c.t | 69 +++++--
libs/core/GP_Fill.gen.c.t | 54 ++++--
libs/core/GP_GammaCorrection.gen.c.t | 45 ++++-
libs/core/GP_Pixel.gen.c.t | 91 +++++----
libs/core/Makefile | 2 +-
libs/core/WritePixels.t | 37 +++-
libs/filters/GP_ApplyTables.gen.c.t | 63 +++++--
libs/filters/GP_Cubic.gen.c.t | 52 ++++-
libs/filters/GP_FloydSteinberg.gen.c.t | 145 ++++++++------
libs/filters/GP_GaussianNoise.gen.c.t | 81 +++++---
libs/filters/GP_HilbertPeano.gen.c.t | 83 ++++++---
libs/filters/GP_LinearConvolution.gen.c.t | 177 ++++++++++-------
libs/filters/GP_MirrorH.gen.c.t | 42 ++++-
libs/filters/GP_MultiTone.gen.c.t | 70 +++++--
libs/filters/GP_ResizeCubic.gen.c.t | 160 +++++++++-------
libs/filters/GP_ResizeLinear.gen.c.t | 203 +++++++++++---------
libs/filters/GP_ResizeNN.gen.c.t | 52 ++++--
libs/filters/GP_Rotate.gen.c.t | 69 +++++---
libs/filters/Makefile | 16 +-
libs/gfx/GP_FillCircle.gen.c.t | 45 ++++-
libs/gfx/GP_FillEllipse.gen.c.t | 42 ++++-
libs/gfx/GP_HLine.gen.c.t | 69 +++++--
libs/gfx/GP_HLineAA.gen.c.t | 8 +-
libs/gfx/GP_Line.gen.c.t | 45 ++++-
libs/gfx/GP_LineAA.gen.c.t | 8 +-
libs/gfx/GP_PutPixelAA.gen.c.t | 9 +-
libs/gfx/GP_VLine.gen.c.t | 38 +++-
libs/gfx/GP_VLineAA.gen.c.t | 8 +-
libs/gfx/Makefile | 2 +-
libs/text/GP_Text.gen.c.t | 91 ++++++---
libs/text/Makefile | 2 +-
tests/core/BlitConv.gen.c.t | 162 ++++++++++------
tests/core/Convert.gen.c.t | 236 +++++++++++++----------
tests/core/Convert_Scale.gen.c.t | 63 +++++--
tests/core/GetPutPixel.gen.c.t | 63 +++++--
tests/core/GetSetBits.gen.c.t | 73 +++++--
tests/core/Makefile | 2 +-
tests/core/WritePixel.gen.c.t | 96 +++++++---
tests/gfx/APICoverage.gen.c.t | 203 ++++++++++++--------
tests/gfx/Makefile | 2 +-
66 files changed, 2478 insertions(+), 2065 deletions(-)
delete mode 100755 gen/bin/cct.py
delete mode 100644 gen/include/functions.t
delete mode 100644 gen/include/gfxprim_config.py
delete mode 100644 gen/include/gfxprimconfig.py
delete mode 100644 gen/include/header.t
delete mode 100644 gen/include/license.t
delete mode 100644 gen/include/pixelsize.py
delete mode 100644 gen/include/pixeltype.py
delete mode 100644 gen/include/source.t
delete mode 100644 genn.mk
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
05 Nov '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 7277e9f644891feda13a940bf14b3a6597d19d9f (commit)
via 1176d24e31d0d820628edf8b4d5ba74db4d51cb5 (commit)
via c962710c01d67f93a2a39d49db5b5a678df8070e (commit)
via c0cfb2f6ac22689db526b97aa65cb0ca89bbb1cf (commit)
from 334730ba119db655383ca862373271fb11fd9d87 (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/7277e9f644891feda13a940bf14b3a6597d1…
commit 7277e9f644891feda13a940bf14b3a6597d19d9f
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Thu Oct 23 15:12:38 2014 +0200
Switch from jinj2 to cct
https://github.com/metan-ucw/cct
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/gen/bin/cct.py b/gen/bin/cct.py
new file mode 100755
index 00000000..29030ba6
--- /dev/null
+++ b/gen/bin/cct.py
@@ -0,0 +1,298 @@
+#!/usr/bin/env python
+#
+# Distributed under GPLv2.1 or any later
+#
+# Copyright (C) 2014 Tomas Gavenciak <gavento(a)ucw.cz>
+# Copyright (C) 2014 Cyril Hrubis <metan(a)ucw.cz>
+#
+
+import re
+import getopt
+from sys import argv, exit
+from os import path, remove, system
+
+def perror(filename, line, lineno, row, error):
+ print('%s:%i:%i: error: %sn' % (filename, lineno, row, error))
+ print(line)
+ print(' ' * row + '^n')
+ exit(1)
+
+# parse {{ expression }} blocks, escape special chars
+def transform_verbatim(filename, line, lineno, startrow=0):
+ tokens = re.split('({{|}})', line)
+ code = '"'
+ row = 0
+ in_code = False
+ for token in tokens:
+ if token == '{{':
+ if in_code:
+ perror(filename, line, lineno, row + startrow, 'Unexpected {{')
+ else:
+ in_code = True
+ code = code + '" + str('
+ elif token == '}}':
+ if in_code:
+ in_code = False
+ code = code + ') + "'
+ else:
+ perror(filename, line, lineno, row + startrow, 'Unexpected }}')
+ else:
+ # escape and " but only in verbatim mode
+ if not in_code:
+ token = token.replace("\", "\").replace('"', '\"')
+ code = code + token
+
+ row += len(token)
+
+ if in_code:
+ perror(filename, line, lineno, row + startrow, 'Unterminated {{')
+
+ return code + '"'
+
+def transform(filename, lines, include_dirs, startindent, indent_depth):
+ out = []
+ lastindent = 0
+ lineno = 0
+
+ for l in lines:
+ lineno += 1
+ l = l.rstrip('n')
+
+ if l == '@':
+ continue;
+
+ if re.match('s*(a)s.*', l):
+ padd = l[:len(l) - len(l.lstrip())]
+ l = l.lstrip()
+ # lines with '@ end' ends intent block by setting new indent
+ if re.match('@s*ends*', l):
+ lastindent = len(l[2:]) - len(l[2:].lstrip())
+ elif re.match('@s*include.*', l):
+ include_filename = re.sub('@s*includes*', '', l)
+ include_path = ''
+
+ if not include_filename:
+ perror(filename, l, lineno, len(l), 'Expected filename')
+
+ for dirname in include_dirs:
+ if path.isfile(dirname + '/' + include_filename):
+ include_path = dirname + '/' + include_filename
+ break
+
+ if not include_path:
+ perror(filename, l, lineno, len(l) - len(include_filename),
+ "Failed to locate '%s' in %s" %
+ (include_filename, include_dirs))
+
+ try:
+ infile = open(include_path, 'r')
+ except Exception as err:
+ perror(filename, l, lineno, len(l) - len(include_filename), str(err))
+
+ out = out + transform(include_filename, infile.readlines(),
+ include_dirs, lastindent + startindent,
+ indent_depth)
+
+ infile.close()
+ else:
+ code = re.sub('t', ' ', l[2:]).rstrip()
+ # full-line comments do not change last indent
+ if code and not re.match('^[ ]*#', code):
+ if code.endswith(':'):
+ lastindent = len(code) - len(code.lstrip()) + indent_depth
+ if (padd):
+ out.append(' ' * startindent + 'cct.set_padd("%s")' % padd)
+ out.append(' ' * startindent + code)
+ if (padd):
+ out.append(' ' * startindent + 'cct.set_padd("")')
+ # special handling for {@ call() @}
+ elif re.match('.*{@.*@}.*', l):
+ tokens = re.split('{@|@}', l)
+ if len(tokens) > 3:
+ row = len((tokens[0] + tokens[1] + tokens[2]).replace('t', ' '))
+ perror(filename, l, lineno, row + 4,
+ "Only one {@ call() @} per line is allowed")
+ prefix = transform_verbatim(filename, tokens[0], lineno)
+ startrow = len((tokens[0] + tokens[1]).replace('t', ' ')) + 2
+ suffix = transform_verbatim(filename, tokens[2], lineno, startrow)
+ out.append(' ' * (lastindent + startindent) + 'cct.set_prefix(' + prefix + ')')
+ out.append(' ' * (lastindent + startindent) + 'cct.set_suffix(' + suffix + ')')
+ out.append(' ' * (lastindent + startindent) + tokens[1].strip())
+ out.append(' ' * (lastindent + startindent) + 'cct.reset()')
+ else:
+ code = transform_verbatim(filename, l, lineno)
+ out.append(' ' * (lastindent + startindent) + 'cct.write(' + code + ')')
+
+ return out
+
+header = [
+ "#!/usr/bin/env python",
+ "#",
+ "# Generated file do _not_ edit by hand!",
+ "#",
+ "from sys import exit",
+ "from os import remove, path",
+ "",
+ "class cct:",
+ " def __init__(self, outfile_path, filename):",
+ " self.first = True",
+ " self.filename = filename",
+ " self.outfile_path = outfile_path",
+ " self.suffix = []",
+ " self.prefix = []",
+ " try:",
+ " self.outfile = open(outfile_path, 'w')",
+ " except Exception as err:",
+ " self.error('Failed to open file: ' + outfile_path + ' : ' + str(err))",
+ "",
+ " def error_cleanup(self):",
+ " self.outfile.close()",
+ " remove(self.outfile_path)",
+ "",
+ " def error(self, string):",
+ " self.error_cleanup()",
+ " print('cct: error: ' + string)",
+ " exit(1)",
+ "",
+ " def write(self, line):",
+ " if self.first:",
+ " if 'cct_header' in globals():",
+ " self.first = False",
+ " cct_header(path.basename(self.outfile_path), self.filename)",
+ " if not line and not ''.join(self.suffix):",
+ " prefix = ''.join(self.prefix).rstrip()",
+ " else:",
+ " prefix = ''.join(self.prefix)",
+ " self.outfile.write(prefix + line + ''.join(self.suffix) + '
')",
+ "",
+ " def set_prefix(self, prefix):",
+ " self.prefix.append(prefix)",
+ "",
+ " def set_suffix(self, suffix):",
+ " self.suffix.append(suffix)",
+ "",
+ " def reset(self):",
+ " self.suffix.pop()",
+ " self.prefix.pop()",
+ "",
+ " def close(self):",
+ " if 'cct_footer' in globals():",
+ " cct_footer(path.basename(self.outfile_path), self.filename)",
+ "",
+ " try:",
+ " self.outfile.close()",
+ " except Exception as err:",
+ " self.error('Failed to write ' + self.outfile_path + ' : ' + str(err))",
+ "",
+]
+
+footer = [
+ "except Exception as err:",
+ " cct.error_cleanup()",
+ " raise",
+ "cct.close()",
+]
+
+def generate(filename, lines, include_dirs, indent_depth, outfile):
+ out = header
+ out.append("cct = cct('%s', '%s')" % (outfile, filename))
+ out.append("")
+ out.append("try:")
+ res = transform(filename, lines, include_dirs, indent_depth, indent_depth)
+ out = out + res + footer
+ return 'n'.join(out)
+
+def error(error):
+ print(error)
+ exit(1)
+
+def usage():
+ print('Usage:ncct [-Idir] [-v] [-o outfile] file.c.tn')
+ print('-EntStops at first phase, leaves python script')
+ print('-intSets indenntation depth, default is 4')
+ print('-IntAdds include path(s)')
+ print('-ontSets output file')
+ print('-vntSets verbose mode')
+ print('-h | --helpntPrints this help.')
+
+def write_script(script_name, t):
+ try:
+ result = open(script_name, 'w')
+ except Exception as err:
+ error('Failed to open file: ' + script_name + ' : ' + str(err))
+
+ result.write(t)
+
+ try:
+ result.close()
+ except Exception as err:
+ error('Failed to close file: ' + script_name + ' : ' + str(err))
+
+def main():
+ try:
+ opts, args = getopt.getopt(argv[1:], 'Eho:i:I:v', ['help'])
+ except getopt.GetoptError as err:
+ print(str(err))
+ usage()
+ exit(1)
+
+ include_dirs = ['.']
+ verbose = False
+ outfile = ''
+ execute = True
+ indent_depth = 4
+
+ for opt, arg in opts:
+ if opt in ('-h', '--help'):
+ usage()
+ exit(0)
+ elif opt == '-i':
+ indent_depth = int(arg)
+ elif opt == '-I':
+ include_dirs.append(arg)
+ elif opt == '-v':
+ verbose = True
+ elif opt == '-o':
+ outfile = arg
+ elif opt == '-E':
+ execute = False
+
+ if len(args) != 1:
+ error('No input files.')
+
+ if not outfile:
+ if not args[0].endswith('.t'):
+ error('No outfile set and template does not end with .t')
+
+ outfile = args[0][:-2]
+
+ if verbose:
+ print("Settingsn--------")
+ print("Include Dirs: %s" % include_dirs)
+ print("Template File: %s" % args[0])
+ print("Output File: %s" % outfile)
+ print("Indentation Depth: %i" % indent_depth)
+ print("")
+
+ with open(args[0], 'rt') as f:
+ t = generate(args[0], f.readlines(), include_dirs, indent_depth, outfile)
+
+ script_name = outfile + '.py'
+
+ if execute:
+ try:
+ glob = {}
+ exec(t, glob)
+ except Exception:
+ # Something failed fallback to writing file
+ # and executing it because the error trace
+ # from exec() tends to be less informative
+ write_script(script_name, t)
+ system('python ' + script_name)
+ remove(script_name)
+ exit(1)
+ else:
+ write_script(script_name, t)
+
+if __name__ == '__main__':
+ main()
diff --git a/gen/include/functions.t b/gen/include/functions.t
new file mode 100644
index 00000000..81e995dd
--- /dev/null
+++ b/gen/include/functions.t
@@ -0,0 +1,48 @@
+@ from gfxprim_config import config
+@ pixelsizes = config.pixelsizes
+@ pixeltypes_dict = config.pixeltypes_dict
+@ pixeltypes = config.pixeltypes
+@ pixelsizes_by_bpp = config.pixelsizes_by_bpp
+@
+@ def arr_to_params(array, prefix='', suffix=''):
+@ res = []
+@ for i in array:
+@ res.append(prefix + str(i) + suffix)
+@ return ', '.join(res)
+@ end
+@
+@ def gamma_in_bits(size):
+@ if size + 2 > 8:
+@ return 16
+@ else:
+@ return 8
+@ end
+@
+@ def gamma_out_bits(size):
+@ if size > 8:
+@ return 16
+@ else:
+@ return 8
+@ end
+@
+@ def fetch_gamma_tables(pt, ctx, pref="", suff=""):
+/* prepare Gamma tables */
+@ for c in pt.chanslist:
+uint{{ gamma_in_bits(c[2]) }}_t *{{ pref + c.name }}_2_LIN{{ suff }} = NULL;
+@ end
+@ for c in pt.chanslist:
+uint{{ gamma_out_bits(c[2]) }}_t *{{ pref + c.name }}_2_GAMMA{{ suff }} = NULL;
+@ end
+@ i = 0
+
+if ({{ ctx }}->gamma) {
+@ for c in pt.chanslist:
+ {{ pref + c.name }}_2_LIN{{ suff }} = {{ ctx }}->gamma->tables[{{ i }}]->u{{ gamma_in_bits(c[2]) }};
+@ i = i + 1
+@ i = len(pt.chanslist)
+@ for c in pt.chanslist:
+ {{ pref + c.name }}_2_GAMMA{{ suff }} = {{ ctx }}->gamma->tables[{{ i }}]->u{{ gamma_out_bits(c[2]) }};
+@ i = i + 1
+@ end
+}
+@ end
diff --git a/gen/include/gfxprim_config.py b/gen/include/gfxprim_config.py
new file mode 100644
index 00000000..3682ccf4
--- /dev/null
+++ b/gen/include/gfxprim_config.py
@@ -0,0 +1,136 @@
+#
+# gfxprim_config.py - module configuring GfxPrim code generation and
+# known PixelTypes
+#
+
+#
+# 2011 Tomas Gavenciak <gavento(a)ucw.cz>
+# 2011-2013 Cyril Hrubis <metan(a)ucw.cz>
+#
+# This file is sourced by all the generating scripts.
+# Moreover, the generated files are sourced by almost all Gfxprim sources,
+# so a complete recompilation is required after any change.
+#
+
+from pixeltype import PixelType
+from pixelsize import PixelSize, LE, BE
+from gfxprimconfig import GfxPrimConfig
+
+# Declared pixel sizes:
+PS_1BPP_LE = PixelSize(1, bit_endian=LE)
+PS_1BPP_BE = PixelSize(1, bit_endian=BE)
+PS_2BPP_LE = PixelSize(2, bit_endian=LE)
+PS_2BPP_BE = PixelSize(2, bit_endian=BE)
+PS_4BPP_LE = PixelSize(4, bit_endian=LE)
+PS_4BPP_BE = PixelSize(4, bit_endian=BE)
+PS_8BPP = PixelSize(8)
+PS_16BPP = PixelSize(16)
+PS_24BPP = PixelSize(24)
+PS_32BPP = PixelSize(32)
+# Experimental:
+PS_18BPP_LE = PixelSize(18, bit_endian=LE)
+
+config = GfxPrimConfig(
+
+ # C name and bit-size of the GP_pixel type
+ pixel_type = "uint32_t",
+ pixel_size = 32,
+
+ # List of pixel sizes (bpp), explicit on purpose
+ pixelsizes = [PS_1BPP_LE, PS_1BPP_BE, PS_2BPP_LE, PS_2BPP_BE, PS_4BPP_LE, PS_4BPP_BE,
+ PS_8BPP, PS_16BPP, PS_24BPP, PS_32BPP,
+ PS_18BPP_LE,
+ ],
+
+ # List of PixelTypes, order defines the numbering.
+ # The "Undefined" type is added automatically.
+ pixeltypes = [
+
+ #
+ # Standard RGB types
+ #
+ PixelType(name='xRGB8888', pixelsize=PS_32BPP, chanslist=[
+ ('R', 16, 8),
+ ('G', 8, 8),
+ ('B', 0, 8)]),
+
+ PixelType(name='RGBA8888', pixelsize=PS_32BPP, chanslist=[
+ ('R', 24, 8),
+ ('G', 16, 8),
+ ('B', 8, 8),
+ ('A', 0, 8)]),
+
+ PixelType(name='RGB888', pixelsize=PS_24BPP, chanslist=[
+ ('R', 16, 8),
+ ('G', 8, 8),
+ ('B', 0, 8)]),
+
+ PixelType(name='BGR888', pixelsize=PS_24BPP, chanslist=[
+ ('B', 16, 8),
+ ('G', 8, 8),
+ ('R', 0, 8)]),
+
+ PixelType(name='RGB555', pixelsize=PS_16BPP, chanslist=[
+ ('R', 10, 5),
+ ('G', 5, 5),
+ ('B', 0, 5)]),
+
+ PixelType(name='RGB565', pixelsize=PS_16BPP, chanslist=[
+ ('R', 11, 5),
+ ('G', 5, 6),
+ ('B', 0, 5)]),
+
+ PixelType(name='RGB666', pixelsize=PS_18BPP_LE, chanslist=[
+ ('R', 12, 6),
+ ('G', 6, 6),
+ ('B', 0, 6)]),
+
+ PixelType(name='RGB332', pixelsize=PS_8BPP, chanslist=[
+ ('R', 5, 3),
+ ('G', 2, 3),
+ ('B', 0, 2)]),
+
+ #
+ # CMYK
+ #
+ PixelType(name="CMYK8888", pixelsize=PS_32BPP, chanslist=[
+ ('K', 24, 8),
+ ('Y', 16, 8),
+ ('M', 8, 8),
+ ('C', 0, 8)]),
+
+ #
+ # Palette types
+ #
+ PixelType(name='P2', pixelsize=PS_2BPP_LE, chanslist=[
+ ('P', 0, 2)]),
+
+ PixelType(name='P4', pixelsize=PS_4BPP_LE, chanslist=[
+ ('P', 0, 4)]),
+
+ PixelType(name='P8', pixelsize=PS_8BPP, chanslist=[
+ ('P', 0, 8)]),
+
+ #
+ # Gray-only pixel types
+ #
+ PixelType(name='G1', pixelsize=PS_1BPP_LE, chanslist=[
+ ('V', 0, 1)]),
+
+ PixelType(name='G2', pixelsize=PS_2BPP_LE, chanslist=[
+ ('V', 0, 2)]),
+
+ PixelType(name='G4', pixelsize=PS_4BPP_LE, chanslist=[
+ ('V', 0, 4)]),
+
+ PixelType(name='G8', pixelsize=PS_8BPP, chanslist=[
+ ('V', 0, 8)]),
+
+ PixelType(name='GA88', pixelsize=PS_16BPP, chanslist=[
+ ('V', 0, 8),
+ ('A', 8, 8)]),
+
+ PixelType(name='G16', pixelsize=PS_16BPP, chanslist=[
+ ('V', 0, 16)]),
+ ]
+ )
diff --git a/gen/include/gfxprimconfig.py b/gen/include/gfxprimconfig.py
new file mode 100644
index 00000000..fb990dff
--- /dev/null
+++ b/gen/include/gfxprimconfig.py
@@ -0,0 +1,73 @@
+#
+# gfxprimconfig - Class for (global) GfxPrim configuration
+#
+# 2011 - Tomas Gavenciak <gavento(a)ucw.cz>
+# 2011 - Cyril Hrubis <metan(a)ucw.cz>
+
+import os
+import logging as log
+from pixeltype import PixelType
+from pixelsize import PixelSize
+
+class GfxPrimConfig(object):
+ def __init__(self, pixel_type = None, pixel_size=None, pixelsizes=None,
+ pixeltypes=None):
+ """Initialize GfxPrim code generation config
+
+ pixel_type: name of C type for a pixel value
+ pixel_size: number of bits of pixel_type
+ pixelsizes: list of generated and allowed PixelSizes
+ pixelsizes_by_bpp: dictionary of bitendians by BPP
+ pixeltypes: list of generated PixelTypes, not incl. UNKNOWN
+ """
+
+ self.pixel_type = pixel_type
+ assert self.pixel_type
+ assert isinstance(self.pixel_type, str)
+
+ self.pixel_size = pixel_size
+ assert isinstance(self.pixel_size, int)
+ assert self.pixel_size % 8 == 0
+ assert self.pixel_size > 0
+
+ # Allowed bit-sizes of pixel types
+ self.pixelsizes = pixelsizes
+ assert isinstance(self.pixelsizes, list)
+ assert self.pixel_size in [i.size for i in self.pixelsizes]
+ for i in self.pixelsizes:
+ assert i.size <= self.pixel_size
+
+ # Dictionary of all pixelsizes by BPP { bpp : list of BE, LE }
+ self.pixelsizes_by_bpp = dict()
+ for i in self.pixelsizes:
+ if i.size not in self.pixelsizes_by_bpp:
+ self.pixelsizes_by_bpp[i.size] = [i.bit_endian]
+ else:
+ self.pixelsizes_by_bpp[i.size].append(i.bit_endian)
+
+ # Set of all encountered channel names
+ self.channels = set()
+
+ # Dictionary of all pixeltypes { name : PixelType }
+ self.pixeltypes_dict = {}
+ # List of all PixelTypes in order. "Unknown" MUST be first.
+ self.pixeltypes = []
+
+ self.add_pixeltype(PixelType("UNKNOWN", PixelSize(0), []))
+ if pixeltypes:
+ for t in pixeltypes:
+ self.add_pixeltype(t)
+
+ def add_pixeltype(self, pixeltype):
+ "Add a PixelType and check its against the config"
+
+ assert pixeltype not in self.pixeltypes
+ self.pixeltypes.append(pixeltype)
+ assert pixeltype.name not in self.pixeltypes_dict
+ self.pixeltypes_dict[pixeltype.name] = pixeltype
+ self.channels.update(set(pixeltype.chans.keys()))
+ try:
+ pixeltype.valid_for_config(self)
+ except AssertionError:
+ log.error("Error checking PixelType %sn" % pixeltype.name)
+
diff --git a/gen/include/header.t b/gen/include/header.t
new file mode 100644
index 00000000..210cf243
--- /dev/null
+++ b/gen/include/header.t
@@ -0,0 +1,11 @@
+@ include functions.t
+@
+@ def cct_header(filename, template):
+@ include license.t
+@ guard = filename.upper().replace('.', '_')
+#ifndef {{ guard }}
+#define {{ guard }}
+
+@ def cct_footer(filename, template):
+@ guard = filename.upper().replace('.', '_')
+#endif /* {{ guard }} */
diff --git a/gen/include/license.t b/gen/include/license.t
new file mode 100644
index 00000000..6d651b5d
--- /dev/null
+++ b/gen/include/license.t
@@ -0,0 +1,10 @@
+@ from datetime import datetime
+/*
+ * Distributed under GPLv2 or any later.
+ *
+ * {{ filename }}
+ *
+ * GENERATED on {{ datetime.now().strftime("%Y %m %d %H:%M:%S") }} from {{ template }}
+ *
+ * DO NOT MODIFY THIS FILE DIRECTLY!
+ */
diff --git a/gen/include/pixelsize.py b/gen/include/pixelsize.py
new file mode 100644
index 00000000..59f7c910
--- /dev/null
+++ b/gen/include/pixelsize.py
@@ -0,0 +1,39 @@
+#
+# gfxprim.pixelsize
+#
+# 2011 - Tomas Gavenciak <gavento(a)ucw.cz>
+#
+
+LE = "LE"
+BE = "BE"
+
+class PixelSize(object):
+ def __init__(self, size, bit_endian=None, suffix=None):
+ self.size = size
+ assert self.size >= 0
+
+ self.bit_endian = bit_endian
+ assert self.bit_endian in [None, LE, BE]
+ assert (bit_endian is not None) == self.needs_bit_endian()
+ self.bit_endian_const = "GP_BIT_ENDIAN_" + (self.bit_endian or LE)
+
+ self.suffix = suffix
+ if not self.suffix:
+ if self.size == 0:
+ self.suffix = "INVALID"
+ else:
+ if bit_endian:
+ self.suffix = '%dBPP_%s' % (size, bit_endian)
+ else:
+ self.suffix = '%dBPP' % (size,)
+
+ def needs_bit_endian(self):
+ return (self.size % 8) != 0
+
+ def description(self):
+ if self.bit_endian:
+ return "pixel size %d, bit endian %s, suffix %s" % (self.size,
+ self.bit_endian, self.suffix)
+ else:
+ return "pixel size %d, suffix %s" % (self.size, self.suffix)
+
diff --git a/gen/include/pixeltype.py b/gen/include/pixeltype.py
new file mode 100644
index 00000000..e42e103e
--- /dev/null
+++ b/gen/include/pixeltype.py
@@ -0,0 +1,104 @@
+#
+# gfxprim.pixeltype - Module with PixelType descrition class
+#
+# 2011 - Tomas Gavenciak <gavento(a)ucw.cz>
+# 2013 Cyril Hrubis <metan(a)ucw.cz>
+#
+
+import re
+from pixelsize import PixelSize
+
+class PixelChannel(list):
+ def __init__(self, triplet, idx):
+ (name, offset, size) = triplet
+ # Create the list -> backward compatibility with triplets
+ self.append(name)
+ self.append(offset)
+ self.append(size)
+ # Add index (position in pixel from left)
+ self.idx = idx
+ # Add some convinience variables
+ self.name = name
+ self.off = offset
+ self.size = size
+ # Shift ready to used in C
+ self.C_shift = " << " + hex(offset)
+ # Maximal channel value as an integer
+ self.max = 2 ** size - 1
+ # Maximal value as a C string
+ self.C_max = hex(self.max)
+ # Chanel bitmask as int
+ self.mask = self.max * (2 ** offset)
+ # Channel bitmas as hex string
+ self.C_mask = hex(self.mask)
+
+class PixelType(object):
+ """Representation of one GP_PixelType"""
+
+ def __init__(self, name, pixelsize, chanslist):
+ """`name` must be a valid C identifier
+ `pixelsize` is an instance of PixelSize
+ `chanslist` is a list of triplets describing individual channels as
+ [ (`chan_name`, `bit_offset`, `bit_size`) ]
+ where `chan_name` is usually one of: R, G, B,
+ V (value, used for grayscale), A (opacity)
+ """
+ assert re.match('A[A-Za-z][A-Za-z0-9_]*Z', name)
+ self.name = name
+ # Create channel list with convinience variables
+ new_chanslist = []
+ self.chan_names = []
+ idx = 0
+ for i in chanslist:
+ new_chanslist.append(PixelChannel(i, idx))
+ idx = idx + 1
+ self.chan_names.append(i[0])
+ self.chanslist = new_chanslist
+ self.chans = dict() # { chan_name: (offset, size) }
+ self.pixelsize = pixelsize
+ # C enum as defined in GP_Pixel.gen.h
+ self.C_type = "GP_PIXEL_" + self.name
+
+ # Verify channel bits for overlaps
+ # also builds a bit-map of the PixelType
+ self.bits = ['x'] * pixelsize.size
+ for c in new_chanslist:
+ assert c[0] not in self.chans.keys()
+ self.chans[c[0]] = c
+ for i in range(c[1], c[1] + c[2]):
+ assert(i < self.pixelsize.size)
+ assert(self.bits[i] == 'x')
+ self.bits[i] = c[0]
+
+ def valid_for_config(self, config):
+ "Check PixelType compatibility with given GfxPrimConfig."
+
+ # all types except UNKNOWN must have one of these sizes
+ if not self.is_unknown():
+ assert(self.pixelsize in config.pixelsizes)
+
+ def __str__(self):
+ return "<PixelType " + self.name + ">"
+
+ def is_palette(self):
+ return ('P' in self.chans)
+
+ def is_unknown(self):
+ return (self.name == "UNKNOWN")
+
+ def is_rgb(self):
+ for i in 'RGB':
+ if i not in self.chans: return False
+ return True
+
+ def is_gray(self):
+ return ('V' in self.chans)
+
+ def is_cmyk(self):
+ for i in 'CMYK':
+ if i not in self.chans: return False
+ return True
+
+ def is_alpha(self):
+ return ('A' in self.chans)
+
diff --git a/gen/include/source.t b/gen/include/source.t
new file mode 100644
index 00000000..f3b08b12
--- /dev/null
+++ b/gen/include/source.t
@@ -0,0 +1,4 @@
+@ include functions.t
+@
+@ def cct_header(filename, template):
+@ include license.t
diff --git a/genn.mk b/genn.mk
new file mode 100644
index 00000000..235cd5fc
--- /dev/null
+++ b/genn.mk
@@ -0,0 +1,48 @@
+#
+# This is makefile rule for generating C sources from python templates
+#
+ifndef GENHEADERS
+GENHEADERS=
+endif
+
+ifndef GENSOURCES
+GENSOURCES=
+endif
+
+#
+# We add these to CSOURCES which is handled in post.mk
+#
+CSOURCES+=$(GENSOURCES)
+
+#
+# Make the genrated headers actually build
+#
+ALL+=$(GENHEADERS) $(GENSOURCES)
+
+#
+# Base common templates location
+#
+TEMPLATEDIR=$(TOPDIR)/gen/include/
+CCT=$(TOPDIR)/gen/bin/cct.py
+
+#
+# And clean them
+#
+CLEAN+=$(GENSOURCES) $(GENHEADERS)
+
+#
+# Some base dependencies
+#
+$(GENSOURCES): $(TEMPLATEDIR)/source.t $(TEMPLATEDIR)/license.t
+$(GENHEADERS): $(TEMPLATEDIR)/header.t $(TEMPLATEDIR)/license.t
+
+#
+# Generated files depend on python generators and the template
+#
+$(GENSOURCES) $(GENHEADERS): %: %.t
+ifdef VERBOSE
+ PYTHONPATH=$(TEMPLATEDIR) ${CCT} -I $(TEMPLATEDIR) "$@.t"
+else
+ @echo "CCT $@"
+ @PYTHONPATH=$(TEMPLATEDIR) ${CCT} -I $(TEMPLATEDIR) "$@.t"
+endif
diff --git a/include/core/GP_Clamp.h b/include/core/GP_Clamp.h
index ac87cb73..bc32507d 100644
--- a/include/core/GP_Clamp.h
+++ b/include/core/GP_Clamp.h
@@ -62,4 +62,11 @@
GP_CLAMP_GENERIC(val, min, max); })
+#define GP_CLAMP_DOWN(val, max) ({ + typeof(val) _val = (val); + typeof(val) _max = (max); + _val = _val > _max ? _max : _val; + _val; +})
+
#endif /* CORE_GP_CLAMP_H */
diff --git a/include/core/GP_Convert.gen.h.t b/include/core/GP_Convert.gen.h.t
index b59990a0..ee266eaf 100644
--- a/include/core/GP_Convert.gen.h.t
+++ b/include/core/GP_Convert.gen.h.t
@@ -1,41 +1,22 @@
-/*****************************************************************************
- * 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) 2011-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * Copyright (C) 2011 Tomas Gavenciak <gavento(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.h.t"
-
-{% block descr %}Convert PixelType values macros and functions{% endblock %}
-
-{# RGB -> CMYK requires special handling #}
-%% macro rgb_to_cmyk(in, out)
-%% set R = in.chans['R']
-%% set G = in.chans['G']
-%% set B = in.chans['B']
-%% set C = out.chans['C']
-%% set M = out.chans['M']
-%% set Y = out.chans['Y']
-%% set K = out.chans['K']
-%% set max_size = max(R.size, G.size, B.size)
-%% set max_val = 2 ** max_size - 1
+@ include header.t
+/*
+ * Convert PixelType values macros and functions
+ *
+ * Copyright (C) 2011-2014 Cyril Hrubis <metan(a)ucw.cz>
+ * Copyright (C) 2011 Tomas Gavenciak <gavento(a)ucw.cz>
+ */
+@
+@ # RGB -> CMYK requires special handling
+@ def rgb_to_cmyk(in_pix, out_pix):
+@ R = in_pix.chans['R']
+@ G = in_pix.chans['G']
+@ B = in_pix.chans['B']
+@ C = out_pix.chans['C']
+@ M = out_pix.chans['M']
+@ Y = out_pix.chans['Y']
+@ K = out_pix.chans['K']
+@ max_size = max(R.size, G.size, B.size)
+@ max_val = 2 ** max_size - 1
GP_Pixel _R = GP_SCALE_VAL_{{ R.size }}_{{ max_size }}(GP_GET_BITS({{ R.off }}+o1, {{ R.size }}, p1)); GP_Pixel _G = GP_SCALE_VAL_{{ G.size }}_{{ max_size }}(GP_GET_BITS({{ G.off }}+o1, {{ G.size }}, p1)); GP_Pixel _B = GP_SCALE_VAL_{{ B.size }}_{{ max_size }}(GP_GET_BITS({{ B.off }}+o1, {{ B.size }}, p1)); @@ -44,85 +25,78 @@
GP_SET_BITS({{ M.off }}+o2, {{ M.size }}, p2, GP_SCALE_VAL_{{ max_size }}_{{ M.size }}((_K - _G))); GP_SET_BITS({{ Y.off }}+o2, {{ Y.size }}, p2, GP_SCALE_VAL_{{ max_size }}_{{ Y.size }}((_K - _B))); GP_SET_BITS({{ K.off }}+o2, {{ K.size }}, p2, GP_SCALE_VAL_{{ max_size }}_{{ K.size }}({{ max_val }} - _K)); -%% endmacro
-
-%% macro GP_Pixel_TYPE_TO_TYPE(pt1, pt2)
+@ end
+@
+@ def GP_Pixel_TYPE_TO_TYPE(pt1, pt2):
/*** {{ pt1.name }} -> {{ pt2.name }} ***
* macro reads p1 ({{ pt1.name }} at bit-offset o1)
* and writes to p2 ({{ pt2.name }} at bit-offset o2)
* the relevant part of p2 is assumed to be cleared (zero) */
#define GP_Pixel_{{ pt1.name }}_TO_{{ pt2.name }}_OFFSET(p1, o1, p2, o2) do { -{# special cases -#}
-%% if pt1.is_rgb() and pt2.is_cmyk()
-{{ rgb_to_cmyk(pt1, pt2) -}}
-%% else
-%% for c2 in pt2.chanslist
-{# case 1: just copy a channel -#}
-%% if c2[0] in pt1.chans.keys()
-%% set c1 = pt1.chans[c2[0]]
+@ # special cases
+@ if pt1.is_rgb() and pt2.is_cmyk():
+@ rgb_to_cmyk(pt1, pt2)
+@ else:
+@ for c2 in pt2.chanslist:
+@ # case 1: just copy a channel
+@ if c2[0] in pt1.chans.keys():
+@ c1 = pt1.chans[c2[0]]
/* {{ c2[0] }}:={{ c1[0] }} */ GP_SET_BITS({{ c2.off }}+o2, {{ c2.size }}, p2, GP_SCALE_VAL_{{ c1.size }}_{{ c2.size }}(GP_GET_BITS({{ c1.off }}+o1, {{ c1.size }}, p1))); -{# case 2: set A to full opacity (not present in source) -#}
-%% elif c2[0]=='A'
+@ # case 2: set A to full opacity (not present in source)
+@ elif c2[0]=='A':
/* A:={{ c2.C_max }} */GP_SET_BITS({{ c2.off }}+o2, {{ c2.size }}, p2, {{ c2.C_max }}); -{# case 3: calculate V as average of RGB -#}
-%% elif c2[0]=='V' and pt1.is_rgb()
+@ # case 3: calculate V as average of RGB
+@ elif c2[0]=='V' and pt1.is_rgb():
/* V:=RGB_avg */ GP_SET_BITS({{ c2.off }}+o2, {{ c2.size }}, p2, ( -%% for c1 in [pt1.chans['R'], pt1.chans['G'], pt1.chans['B']]
+@ for c1 in [pt1.chans['R'], pt1.chans['G'], pt1.chans['B']]:
/* {{ c1.name }} */ GP_SCALE_VAL_{{ c1.size }}_{{ c2.size }}(GP_GET_BITS({{ c1.off }}+o1, {{ c1.size }}, p1)) + -%% endfor
+@ end
0)/3);-{# case 4: set each RGB to V -#}
-%% elif c2[0] in 'RGB' and pt1.is_gray()
-%% set c1 = pt1.chans['V']
+@ # case 4: set each RGB to V -#}
+@ elif c2[0] in 'RGB' and pt1.is_gray():
+@ c1 = pt1.chans['V']
/* {{ c2[0] }}:=V */ GP_SET_BITS({{ c2.off }}+o2, {{ c2.size }}, p2, GP_SCALE_VAL_{{ c1.size }}_{{ c2.size }}(GP_GET_BITS({{ c1.off }}+o1, {{ c1.size }}, p1))); -{# case 5: CMYK to RGB -#}
-%% elif c2[0] in 'RGB' and pt1.is_cmyk()
-%% set K = pt1.chans['K']
-{# Get the right channel -#}
-%% if c2[0] == 'R'
-%% set V = pt1.chans['C']
-%% elif c2[0] == 'G'
-%% set V = pt1.chans['M']
-%% else
-%% set V = pt1.chans['Y']
-%% endif
+@ # case 5: CMYK to RGB
+@ elif c2[0] in 'RGB' and pt1.is_cmyk():
+@ K = pt1.chans['K']
+@ if c2[0] == 'R':
+@ V = pt1.chans['C']
+@ elif c2[0] == 'G':
+@ V = pt1.chans['M']
+@ else:
+@ V = pt1.chans['Y']
+@ end
GP_SET_BITS({{ c2.off }}+o2, {{ c2.size }}, p2, (({{ c2.C_max }} * ({{ K.C_max }} - GP_GET_BITS({{ K.off }}+o1, {{ K.size }}, p1)) * ({{ V.C_max }} - GP_GET_BITS({{ V.off }}+o1, {{ V.size }}, p1)))) / ({{ K.C_max }} * {{ V.C_max }})); -{# case 7: invalid mapping -#}
-%% else
+@ # case 7: invalid mapping
+@ else:
{{ error('Channel conversion ' + pt1.name + ' to ' + pt2.name + ' not supported.') }}
-%% endif
-%% endfor
-%% endif
+@ end
} while (0)
/* a version without offsets */
#define GP_Pixel_{{ pt1.name }}_TO_{{ pt2.name }}(p1, p2) GP_Pixel_{{ pt1.name }}_TO_{{ pt2.name }}_OFFSET(p1, 0, p2, 0)
-%% endmacro
+@ end
-
-%% block body
#include "GP_GetSetBits.h"
#include "GP_Context.h"
#include "GP_Pixel.h"
-{#
- # Loop around "central" pixel types
--#}
-%% for pt in [pixeltypes_dict['RGB888'], pixeltypes_dict['RGBA8888']]
-%% for i in pixeltypes
-%% if not i.is_unknown() and not i.is_palette()
-{{ GP_Pixel_TYPE_TO_TYPE(pt, i) }}
-%% if i.name not in ['RGB888', 'RGBA8888']
-{{ GP_Pixel_TYPE_TO_TYPE(i, pt) }}
-%% endif
-%% endif
-%% endfor
+@
+@ # Loop around "central" pixel types
+@
+@ for pt in [pixeltypes_dict['RGB888'], pixeltypes_dict['RGBA8888']]:
+@ for i in pixeltypes:
+@ if not i.is_unknown() and not i.is_palette():
+@ GP_Pixel_TYPE_TO_TYPE(pt, i)
+@ if i.name not in ['RGB888', 'RGBA8888']:
+@ GP_Pixel_TYPE_TO_TYPE(i, pt)
+@ end
/*
* Convert {{ pt.name }} to any other PixelType
@@ -136,10 +110,8 @@ GP_Pixel GP_{{ pt.name }}ToPixel(GP_Pixel pixel, GP_PixelType type);
*/
GP_Pixel GP_PixelTo{{ pt.name }}(GP_Pixel pixel, GP_PixelType type);
-%% endfor
+@ end
/* Experimental macros testing generated scripts */
-{{ GP_Pixel_TYPE_TO_TYPE(pixeltypes_dict['RGB565'], pixeltypes_dict['RGBA8888']) }}
-{{ GP_Pixel_TYPE_TO_TYPE(pixeltypes_dict['RGBA8888'], pixeltypes_dict['G2']) }}
-
-%% endblock body
+@ GP_Pixel_TYPE_TO_TYPE(pixeltypes_dict['RGB565'], pixeltypes_dict['RGBA8888'])
+@ GP_Pixel_TYPE_TO_TYPE(pixeltypes_dict['RGBA8888'], pixeltypes_dict['G2'])
diff --git a/include/core/GP_Convert_Scale.gen.h.t b/include/core/GP_Convert_Scale.gen.h.t
index b0156ad4..335cdbd9 100644
--- a/include/core/GP_Convert_Scale.gen.h.t
+++ b/include/core/GP_Convert_Scale.gen.h.t
@@ -1,35 +1,15 @@
-/*****************************************************************************
- * 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) 2011 Tomas Gavenciak <gavento(a)ucw.cz> *
- * Copyright (C) 2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.h.t"
-
-{% block descr %}Fast value scaling macros{% endblock %}
+@ include header.t
+/*
+ * Fast value scaling macros
+ *
+ * Copyright (C) 2011 Tomas Gavenciak <gavento(a)ucw.cz>
+ * Copyright (C) 2013-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
-{% macro multcoef(s1, s2) -%}
-(0{% for i in range((s2 + s1 - 1) // s1) %}+{{ hex(2 ** (i * s1)) }}{% endfor %})
-{%- endmacro %}
+@ def multcoef(s1, s2):
+(0+{{'+'.join([hex(2 ** (i * s1)) for i in range((s2 + s1 - 1)//s1)])}})
+@ end
-%% block body
/*
* Helper macros to transfer s1-bit value to s2-bit value.
* Efficient and accurate for both up- and downscaling.
@@ -37,14 +17,9 @@
*/
#define GP_SCALE_VAL(s1, s2, val) ( GP_SCALE_VAL_##s1##_##s2(val) )
-%% for s1 in range(1,33)
-%% for s2 in range(1,17)
-%% if s2 > s1
-#define GP_SCALE_VAL_{{s1}}_{{s2}}(val) (((val) * {{ multcoef(s1, s2) }}) >> {{ (-s2) % s1 }})
-%% else
+@ for s1 in range(1,33):
+@ for s2 in range(1,17):
+@ if s2 > s1:
+#define GP_SCALE_VAL_{{s1}}_{{s2}}(val) (((val) * {@ multcoef(s1, s2) @}) >> {{ (-s2) % s1 }})
+@ else:
#define GP_SCALE_VAL_{{s1}}_{{s2}}(val) ((val) >> {{ s1 - s2 }})
-%% endif
-%% endfor
-%% endfor
-
-%% endblock body
diff --git a/include/core/GP_FnPerBpp.gen.h.t b/include/core/GP_FnPerBpp.gen.h.t
index 9b1cdcdb..e2364e5f 100644
--- a/include/core/GP_FnPerBpp.gen.h.t
+++ b/include/core/GP_FnPerBpp.gen.h.t
@@ -1,58 +1,42 @@
-/*****************************************************************************
- * 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) 2011-2012 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends 'base.h.t'
-
-{% block descr %}All FnPerBpp macros{% endblock %}
-
-{% block body %}
+@ include header.t
+/*
+ * All FnPerBpp macros
+ *
+ * Copyright (C) 2011-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
/*
* Macros used to create draving functions from macros.
*/
#define GP_DEF_FN_PER_BPP(fname, MACRO_NAME, fdraw) -%% for ps in pixelsizes
+@ for ps in pixelsizes:
GP_DEF_FN_FOR_BPP(fname, MACRO_NAME, fdraw, {{ ps.suffix }}) -{% endfor %}
+@ end
+@
+@ def bpp_suffix(suffix):
+@ if suffix == "LE" or suffix == "BE":
+_{{ suffix }}
+@ else:
-{% macro bpp_suffix(suffix) %}{% if suffix == "LE" or suffix == "BE" %}_{{ suffix }}{% endif %}{% endmacro %}
+@ end
/*
* Branch on bpp and bit_endian.
*/
#define GP_FN_PER_BPP(FN_NAME, bpp, bit_endian, ...) switch (bpp) { -%% for bpp in pixelsizes_by_bpp.keys()
+@ for bpp in pixelsizes_by_bpp.keys():
case {{ bpp }}: -%% if len(pixelsizes_by_bpp[bpp]) == 1
- FN_NAME##_{{ bpp }}BPP{{ bpp_suffix(pixelsizes_by_bpp[bpp][0]) }}(__VA_ARGS__); -%% else
+@ if len(pixelsizes_by_bpp[bpp]) == 1:
+ FN_NAME##_{{ bpp }}BPP{@ bpp_suffix(pixelsizes_by_bpp[bpp][0]) @}(__VA_ARGS__); +@ else:
if (bit_endian == GP_BIT_ENDIAN_LE) FN_NAME##_{{ bpp }}BPP_LE(__VA_ARGS__); else FN_NAME##_{{ bpp }}BPP_BE(__VA_ARGS__); -%% endif
+@ end
break; -%% endfor
+@ end
}
/*
@@ -60,18 +44,17 @@
*/
#define GP_FN_RET_PER_BPP(FN_NAME, bpp, bit_endian, ...) switch (bpp) { -%% for bpp in pixelsizes_by_bpp.keys()
+@ for bpp in pixelsizes_by_bpp.keys():
case {{ bpp }}: -%% if len(pixelsizes_by_bpp[bpp]) == 1
- return FN_NAME##_{{ bpp }}BPP{{ bpp_suffix(pixelsizes_by_bpp[bpp][0]) }}(__VA_ARGS__); -%% else
+@ if len(pixelsizes_by_bpp[bpp]) == 1:
+ return FN_NAME##_{{ bpp }}BPP{@ bpp_suffix(pixelsizes_by_bpp[bpp][0]) @}(__VA_ARGS__); +@ else:
if (bit_endian == GP_BIT_ENDIAN_LE) return FN_NAME##_{{ bpp }}BPP_LE(__VA_ARGS__); else return FN_NAME##_{{ bpp }}BPP_BE(__VA_ARGS__); -%% endif
+@ end
break; -%% endfor
+@ end
}
-{% endblock body %}
diff --git a/include/core/GP_GammaCorrection.gen.h.t b/include/core/GP_GammaCorrection.gen.h.t
index 76df078f..59610665 100644
--- a/include/core/GP_GammaCorrection.gen.h.t
+++ b/include/core/GP_GammaCorrection.gen.h.t
@@ -1,49 +1,24 @@
-/*****************************************************************************
- * 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) 2012 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.h.t"
-
-{% block descr %}Gamma corrections.{% endblock %}
-
-%% block body
-
+@ include header.t
+/*
+ * Gamma corrections
+ *
+ * Copyright (C) 2012-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
extern uint16_t *GP_Gamma8_Linear10;
extern uint8_t *GP_Linear10_Gamma8;
-%% for i in range(1, 9)
+@ for i in range(1, 9):
static inline uint16_t GP_Gamma{{ i }}ToLinear10(uint8_t val)
{
return GP_Gamma8_Linear10[val<<{{8 - i}}];
}
-%% endfor
-
-%% for i in range(1, 9)
+@ end
+@ for i in range(1, 9):
static inline uint8_t GP_Linear10ToGamma{{ i }}(uint16_t val)
{
return (GP_Linear10_Gamma8[val] + {{ int(2 ** (7 - i))}})>>{{8 - i}};
}
-%% endfor
-
-%% endblock body
+@ end
diff --git a/include/core/GP_GammaPixel.gen.h.t b/include/core/GP_GammaPixel.gen.h.t
index cefb5cca..14ace8a4 100644
--- a/include/core/GP_GammaPixel.gen.h.t
+++ b/include/core/GP_GammaPixel.gen.h.t
@@ -1,39 +1,18 @@
-/*****************************************************************************
- * 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) 2012 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.h.t"
-
-{% block descr %}Gamma correction for pixels.{% endblock %}
-
-%% block body
+@ include header.t
+/*
+ * Gamma correction for pixels
+ *
+ * Copyright (C) 2012-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include "GP_Context.h"
#include "GP_GammaCorrection.h"
-%% for pt in pixeltypes
-%% if not pt.is_unknown() and not pt.is_palette()
-%% set idx = 0
+@ for pt in pixeltypes:
+@ if not pt.is_unknown() and not pt.is_palette():
+@ idx = 0
-%% for c in pt.chanslist
+@ for c in pt.chanslist:
/*
* Converts gamma encoded pixel value to linear value.
@@ -41,11 +20,11 @@
* Parameters are, converted value and GP_Gamma structure.
*/
#define GP_Gamma2Lin_{{ pt.name }}_{{ c[0] }}(val, gamma) ({ -%% if c[2] > 6
+@ if c[2] > 6:
gamma->tables[{{ idx }}]->u16[val]; -%% else
+@ else:
gamma->tables[{{ idx }}]->u8[val]; -%% endif
+@ end
})
/*
@@ -54,11 +33,11 @@
* Parameters are, converted value and GP_Gamma structure.
*/
#define GP_Lin2Gamma_{{ pt.name }}_{{ c[0] }}(val, gamma) ({ -%% if c[2] > 8
+@ if c[2] > 8:
gamma->tables[{{ len(pt.chanslist) + idx}}]->u16[val]; -%% else
+@ else:
gamma->tables[{{ len(pt.chanslist) + idx}}]->u8[val]; -%% endif
+@ end
})
static inline GP_GammaTable *GP_GammaTable_{{ pt.name }}_{{ c[0] }}(GP_Gamma *gamma)
@@ -71,10 +50,8 @@ static inline GP_GammaTable *GP_GammaInverseTable_{{ pt.name }}_{{ c[0] }}(GP_Ga
return gamma->tables[{{ len(pt.chanslist) + idx }}];
}
-%% set idx = idx + 1
-%% endfor
-%% endif
-%% endfor
+@ idx = idx + 1
+@ end
#define GP_Gamma2Lin(val, chan_bits, gamma_table) ({ #if chan_bits > 6
@@ -91,5 +68,3 @@ static inline GP_GammaTable *GP_GammaInverseTable_{{ pt.name }}_{{ c[0] }}(GP_Ga
gamma_table->table8[val] #endif
})
-
-%% endblock body
diff --git a/include/core/GP_GetPutPixel.gen.h.t b/include/core/GP_GetPutPixel.gen.h.t
index 28ee82d7..39c4d06c 100644
--- a/include/core/GP_GetPutPixel.gen.h.t
+++ b/include/core/GP_GetPutPixel.gen.h.t
@@ -1,35 +1,11 @@
-/*****************************************************************************
- * 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) 2011 Cyril Hrubis <metan(a)ucw.cz> *
- * Copyright (C) 2011 Tomas Gavenciak <gavento(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.h.t"
-
-%% block descr
-Access pixel bytes, Get and PutPixel
-Do not include directly, use GP_Pixel.h
-%% endblock
-
-%% block body
-
+@ include header.t
+/*
+ * Access pixel bytes, Get and PutPixel
+ * Do not include directly, use GP_Pixel.h
+ *
+ * Copyright (C) 2011-2014 Cyril Hrubis <metan(a)ucw.cz>
+ * Copyright (C) 2011 Tomas Gavenciak <gavento(a)ucw.cz>
+ */
/*
@@ -75,7 +51,7 @@ Do not include directly, use GP_Pixel.h
#include "GP_GetSetBits.h"
#include "GP_Context.h"
-%% for ps in pixelsizes
+@ for ps in pixelsizes:
/*
* macro to get address of pixel in a {{ ps.suffix }} context
*/
@@ -86,45 +62,42 @@ Do not include directly, use GP_Pixel.h
* macro to get bit-offset of pixel in {{ ps.suffix }} context
*/
#define GP_PIXEL_ADDR_OFFSET_{{ ps.suffix }}(x) -%% if not ps.needs_bit_endian()
+@ if not ps.needs_bit_endian():
(0)
-%% else
-%% if ps.bit_endian == LE
-%% if ps.size < 8
+@ else:
+@ if ps.bit_endian == 'LE':
+@ if ps.size < 8:
(((x) % {{ 8 // ps.size }}) * {{ ps.size }})
-%% else
+@ else:
(({{ ps.size }} * (x)) % 8)
-%% endif
-%% else
-%% if ps.size < 8
+@ else:
+@ if ps.size < 8:
({{ 8 - ps.size }} - ((x) % {{ 8 // ps.size }}) * {{ ps.size }})
-%% else
+@ else:
{{ error('Insanity check: big bit-endian with >8 bpp. Are you sure?') }}
-%% endif
-%% endif
-%% endif
+@ end
/*
* GP_GetPixel for {{ ps.suffix }}
*/
static inline GP_Pixel GP_GetPixel_Raw_{{ ps.suffix }}(const GP_Context *c, int x, int y)
{
-%% if ps.size == 32
+@ if ps.size == 32:
/*
* 32 BPP is expected to have aligned pixels
*/
return *((uint32_t*)GP_PIXEL_ADDR_{{ ps.suffix }}(c, x, y));
-%% elif ps.size == 16
+@ elif ps.size == 16:
/*
* 16 BPP is expected to have aligned pixels
*/
return *((uint16_t*)GP_PIXEL_ADDR_{{ ps.suffix }}(c, x, y));
-%% elif ps.size == 8
+@ elif ps.size == 8:
/*
* 8 BPP is byte aligned
*/
return *((uint8_t*)GP_PIXEL_ADDR_{{ ps.suffix }}(c, x, y));
-%% elif ps.size == 1 or ps.size == 2 or ps.size == 4 or ps.size == 8
+@ elif ps.size == 1 or ps.size == 2 or ps.size == 4 or ps.size == 8:
/*
* Whole pixel is stored only and only in one byte
*
@@ -132,7 +105,7 @@ static inline GP_Pixel GP_GetPixel_Raw_{{ ps.suffix }}(const GP_Context *c, int
*/
return GP_GET_BITS1_ALIGNED(GP_PIXEL_ADDR_OFFSET_{{ ps.suffix }}(x), {{ ps.size }},
*(GP_PIXEL_ADDR_{{ ps.suffix }}(c, x, y)));
-%% elif ps.size <= 10 or ps.size == 12 or ps.size == 16
+@ elif ps.size <= 10 or ps.size == 12 or ps.size == 16:
/*
* The pixel is stored in one or two bytes
*
@@ -146,7 +119,7 @@ static inline GP_Pixel GP_GetPixel_Raw_{{ ps.suffix }}(const GP_Context *c, int
*/
return GP_GET_BITS2_ALIGNED(GP_PIXEL_ADDR_OFFSET_{{ ps.suffix }}(x), {{ ps.size }},
*(GP_PIXEL_ADDR_{{ ps.suffix }}(c, x, y)));
-%% elif ps.size <= 18 or ps.size == 20 or ps.size == 24
+@ elif ps.size <= 18 or ps.size == 20 or ps.size == 24:
/*
* The pixel is stored in two or three bytes
*
@@ -160,7 +133,7 @@ static inline GP_Pixel GP_GetPixel_Raw_{{ ps.suffix }}(const GP_Context *c, int
*/
return GP_GET_BITS3_ALIGNED(GP_PIXEL_ADDR_OFFSET_{{ ps.suffix }}(x), {{ ps.size }},
*(GP_PIXEL_ADDR_{{ ps.suffix }}(c, x, y)));
-%% elif ps.size <= 23 or ps.size == 25 or ps.size == 26 or ps.size == 28 or ps.size == 32
+@ elif ps.size <= 23 or ps.size == 25 or ps.size == 26 or ps.size == 28 or ps.size == 32:
/*
* The pixel is stored in three or four bytes
*
@@ -174,9 +147,9 @@ static inline GP_Pixel GP_GetPixel_Raw_{{ ps.suffix }}(const GP_Context *c, int
*/
return GP_GET_BITS4_ALIGNED(GP_PIXEL_ADDR_OFFSET_{{ ps.suffix }}(x), {{ ps.size }},
*(GP_PIXEL_ADDR_{{ ps.suffix }}(c, x, y)));
-%% else
+@ else:
#error not implemented
-%% endif
+@ end
}
/*
@@ -184,22 +157,22 @@ static inline GP_Pixel GP_GetPixel_Raw_{{ ps.suffix }}(const GP_Context *c, int
*/
static inline void GP_PutPixel_Raw_{{ ps.suffix }}(GP_Context *c, int x, int y, GP_Pixel p)
{
-%% if ps.size == 32
+@ if ps.size == 32:
/*
* 32 BPP is expected to have aligned pixels
*/
*((uint32_t*)GP_PIXEL_ADDR_{{ ps.suffix }}(c, x, y)) = p;
-%% elif ps.size == 16
+@ elif ps.size == 16:
/*
* 16 BPP is expected to have aligned pixels
*/
*((uint16_t*)GP_PIXEL_ADDR_{{ ps.suffix }}(c, x, y)) = p;
-%% elif ps.size == 8
+@ elif ps.size == 8:
/*
* 8 BPP is byte aligned
*/
*((uint8_t*)GP_PIXEL_ADDR_{{ ps.suffix }}(c, x, y)) = p;
-%% elif ps.size == 1 or ps.size == 2 or ps.size == 4 or ps.size == 8
+@ elif ps.size == 1 or ps.size == 2 or ps.size == 4 or ps.size == 8:
/*
* Whole pixel is stored only and only in one byte
*
@@ -207,7 +180,7 @@ static inline void GP_PutPixel_Raw_{{ ps.suffix }}(GP_Context *c, int x, int y,
*/
GP_SET_BITS1_ALIGNED(GP_PIXEL_ADDR_OFFSET_{{ ps.suffix }}(x), {{ ps.size }},
GP_PIXEL_ADDR_{{ ps.suffix }}(c, x, y), p);
-%% elif ps.size <= 10 or ps.size == 12 or ps.size == 16
+@ elif ps.size <= 10 or ps.size == 12 or ps.size == 16:
/*
* The pixel is stored in one or two bytes
*
@@ -221,7 +194,7 @@ static inline void GP_PutPixel_Raw_{{ ps.suffix }}(GP_Context *c, int x, int y,
*/
GP_SET_BITS2_ALIGNED(GP_PIXEL_ADDR_OFFSET_{{ ps.suffix }}(x), {{ ps.size }},
GP_PIXEL_ADDR_{{ ps.suffix }}(c, x, y), p);
-%% elif ps.size <= 18 or ps.size == 20 or ps.size == 24
+@ elif ps.size <= 18 or ps.size == 20 or ps.size == 24:
/*
* The pixel is stored in two or three bytes
*
@@ -235,7 +208,7 @@ static inline void GP_PutPixel_Raw_{{ ps.suffix }}(GP_Context *c, int x, int y,
*/
GP_SET_BITS3_ALIGNED(GP_PIXEL_ADDR_OFFSET_{{ ps.suffix }}(x), {{ ps.size }},
GP_PIXEL_ADDR_{{ ps.suffix }}(c, x, y), p);
-%% elif ps.size <= 23 or ps.size == 25 or ps.size == 26 or ps.size == 28 or ps.size == 32
+@ elif ps.size <= 23 or ps.size == 25 or ps.size == 26 or ps.size == 28 or ps.size == 32:
/*
* The pixel is stored in three or four bytes
*
@@ -249,9 +222,9 @@ static inline void GP_PutPixel_Raw_{{ ps.suffix }}(GP_Context *c, int x, int y,
*/
GP_SET_BITS4_ALIGNED(GP_PIXEL_ADDR_OFFSET_{{ ps.suffix }}(x), {{ ps.size }},
GP_PIXEL_ADDR_{{ ps.suffix }}(c, x, y), p);
-%% else
+@ else:
#error not implemented
-%% endif
+@ end
}
static inline void GP_PutPixel_Raw_Clipped_{{ ps.suffix }}(GP_Context *c, GP_Coord x, GP_Coord y, GP_Pixel p)
@@ -262,6 +235,3 @@ static inline void GP_PutPixel_Raw_Clipped_{{ ps.suffix }}(GP_Context *c, GP_Coo
GP_PutPixel_Raw_{{ ps.suffix }}(c, x, y, p);
}
-%% endfor
-
-%% endblock body
diff --git a/include/core/GP_MixPixels.gen.h.t b/include/core/GP_MixPixels.gen.h.t
index 7333fe9f..518ed9bc 100644
--- a/include/core/GP_MixPixels.gen.h.t
+++ b/include/core/GP_MixPixels.gen.h.t
@@ -1,40 +1,17 @@
-/*****************************************************************************
- * 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) 2011-2012 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.h.t"
-
-%% block descr
-Macros to mix two pixels accordingly to percentage.
-%% endblock
-
-%% block body
+@ include header.t
+/*
+ * Macros to mix two pixels accordingly to percentage.
+ *
+ * Copyright (C) 2011-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include "core/GP_Context.h"
#include "core/GP_Pixel.h"
#include "core/GP_GetPutPixel.h"
#include "core/GP_GammaCorrection.h"
-%% for pt in pixeltypes
-%% if not pt.is_unknown()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown():
/*
* Mixes two {{ pt.name }} pixels.
@@ -42,16 +19,16 @@ Macros to mix two pixels accordingly to percentage.
* The percentage is expected as 8 bit unsigned integer [0 .. 255]
*/
#define GP_MIX_PIXELS_LINEAR_{{ pt.name }}(pix1, pix2, perc) ({ -%% for c in pt.chanslist
+@ for c in pt.chanslist:
GP_Pixel {{ c[0] }}; {{ c[0] }} = GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix1) * (perc); {{ c[0] }} += GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix2) * (255 - (perc)); {{ c[0] }} = ({{ c[0] }} + 128) / 255; -%% endfor
+@ end
- GP_Pixel_CREATE_{{ pt.name }}({{ pt.chanslist[0][0] }}{% for c in pt.chanslist[1:] %}, {{ c[0] }}{% endfor %}); + GP_Pixel_CREATE_{{ pt.name }}({{ ', '.join(pt.chan_names) }}); })
/*
@@ -60,7 +37,7 @@ Macros to mix two pixels accordingly to percentage.
* The percentage is expected as 8 bit unsigned integer [0 .. 255]
*/
#define GP_MIX_PIXELS_GAMMA_{{ pt.name }}(pix1, pix2, perc) ({ -%% for c in pt.chanslist
+@ for c in pt.chanslist:
GP_Pixel {{ c[0] }}; {{ c[0] }} = GP_Gamma{{ c[2] }}ToLinear10(GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix1)) * (perc); @@ -68,39 +45,35 @@ Macros to mix two pixels accordingly to percentage.
{{ c[0] }} = ({{ c[0] }} + 128) / 255; {{ c[0] }} = GP_Linear10ToGamma{{ c[2] }}({{ c[0] }}); -%% endfor
+@ end
- GP_Pixel_CREATE_{{ pt.name }}({{ pt.chanslist[0][0] }}{% for c in pt.chanslist[1:] %}, {{ c[0] }}{% endfor %}); + GP_Pixel_CREATE_{{ pt.name }}({{ ", ".join(pt.chan_names) }}); })
#define GP_MIX_PIXELS_{{ pt.name }}(pix1, pix2, perc) -%% if pt.is_rgb()
+@ if pt.is_rgb():
GP_MIX_PIXELS_LINEAR_{{ pt.name }}(pix1, pix2, perc)
-%% else
+@ else:
GP_MIX_PIXELS_LINEAR_{{ pt.name }}(pix1, pix2, perc)
-%% endif
-
-%% endif
-%% endfor
+@ end
static inline GP_Pixel GP_MixPixels(GP_Pixel pix1, GP_Pixel pix2,
uint8_t perc, GP_PixelType pixel_type)
{
switch (pixel_type) {
-%% for pt in pixeltypes
-%% if not pt.is_unknown()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown():
case GP_PIXEL_{{ pt.name }}:
return GP_MIX_PIXELS_LINEAR_{{ pt.name }}(pix1, pix2, perc);
-%% endif
-%% endfor
+@ end
default:
GP_ABORT("Unknown pixeltype");
}
}
-%% for pt in pixeltypes
-%% if not pt.is_unknown()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown():
static inline void GP_MixPixel_Raw_{{ pt.name }}(GP_Context *context,
GP_Coord x, GP_Coord y, GP_Pixel pixel, uint8_t perc)
{
@@ -109,11 +82,10 @@ static inline void GP_MixPixel_Raw_{{ pt.name }}(GP_Context *context,
GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(context, x, y, pix);
}
-%% endif
-%% endfor
+@ end
-%% for pt in pixeltypes
-%% if not pt.is_unknown()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown():
static inline void GP_MixPixel_Raw_Clipped_{{ pt.name }}(GP_Context *context,
GP_Coord x, GP_Coord y, GP_Pixel pixel, uint8_t perc)
{
@@ -123,20 +95,18 @@ static inline void GP_MixPixel_Raw_Clipped_{{ pt.name }}(GP_Context *context,
GP_MixPixel_Raw_{{ pt.name }}(context, x, y, pixel, perc);
}
-%% endif
-%% endfor
+@ end
static inline void GP_MixPixel_Raw(GP_Context *context, GP_Coord x, GP_Coord y,
GP_Pixel pixel, uint8_t perc)
{
switch (context->pixel_type) {
-%% for pt in pixeltypes
-%% if not pt.is_unknown()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown():
case GP_PIXEL_{{ pt.name }}:
GP_MixPixel_Raw_{{ pt.name }}(context, x, y, pixel, perc);
break;
-%% endif
-%% endfor
+@ end
default:
GP_ABORT("Unknown pixeltype");
}
@@ -147,16 +117,14 @@ static inline void GP_MixPixel_Raw_Clipped(GP_Context *context,
GP_Pixel pixel, uint8_t perc)
{
switch (context->pixel_type) {
-%% for pt in pixeltypes
-%% if not pt.is_unknown()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown():
case GP_PIXEL_{{ pt.name }}:
GP_MixPixel_Raw_Clipped_{{ pt.name }}(context, x, y, pixel, perc);
break;
-%% endif
-%% endfor
+@ end
default:
GP_ABORT("Unknown pixeltype");
}
}
-%% endblock body
diff --git a/include/core/GP_MixPixels2.gen.h.t b/include/core/GP_MixPixels2.gen.h.t
index 084ae551..d2ffcd1a 100644
--- a/include/core/GP_MixPixels2.gen.h.t
+++ b/include/core/GP_MixPixels2.gen.h.t
@@ -1,43 +1,20 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.h.t"
-
-%%- block descr
-Macros to mix two pixels. The source must have alpha channel.
-%%- endblock
-
-%% block body
+@ include header.t
+/*
+ * Macros to mix two pixels. The source must have alpha channel.
+ *
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include "core/GP_GammaCorrection.h"
#include "core/GP_Pixel.h"
//TODO: Fix blit where both source and destination have alpha channel
-%% for src in pixeltypes
-%% if not src.is_unknown() and not src.is_palette()
-%% for dst in pixeltypes
-%% if not dst.is_unknown() and not dst.is_palette()
-%% if src.is_alpha()
+@ for src in pixeltypes:
+@ if not src.is_unknown() and not src.is_palette():
+@ for dst in pixeltypes:
+@ if not dst.is_unknown() and not dst.is_palette():
+@ if src.is_alpha():
static inline GP_Pixel GP_MixPixels_{{ src.name }}_{{ dst.name }}(GP_Pixel src, GP_Pixel dst)
{
@@ -61,7 +38,7 @@ static inline GP_Pixel GP_MixPixels_{{ src.name }}_{{ dst.name }}(GP_Pixel src,
dg = GP_Pixel_GET_G_RGB888(dst_rgb);
db = GP_Pixel_GET_B_RGB888(dst_rgb);
-%% set a_max = 2 ** src.chans['A'][2] - 1
+@ a_max = 2 ** src.chans['A'][2] - 1
dr = (dr * ({{ a_max }} - alpha) + sr * alpha + {{ a_max // 2 }}) / {{ a_max }};
dg = (dg * ({{ a_max }} - alpha) + sg * alpha + {{ a_max // 2 }}) / {{ a_max }};
@@ -74,10 +51,3 @@ static inline GP_Pixel GP_MixPixels_{{ src.name }}_{{ dst.name }}(GP_Pixel src,
return res;
}
-%% endif
-%% endif
-%% endfor
-%% endif
-%% endfor
-
-%% endblock
diff --git a/include/core/GP_Pixel.gen.h.t b/include/core/GP_Pixel.gen.h.t
index 2bc54690..eba8b3ea 100644
--- a/include/core/GP_Pixel.gen.h.t
+++ b/include/core/GP_Pixel.gen.h.t
@@ -1,68 +1,45 @@
-/*****************************************************************************
- * 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) 2011 Tomas Gavenciak <gavento(a)ucw.cz> *
- * Copyright (C) 2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.h.t"
-
-%% block descr
-Pixel type definitions and functions.
-Do not include directly, use GP_Pixel.h
-%% endblock
-
-%% block body
+@ include header.t
+/*
+ * Pixel type definitions and functions.
+ * Do not include directly, use GP_Pixel.h
+ *
+ * Copyright (C) 2011 Tomas Gavenciak <gavento(a)ucw.cz>
+ * Copyright (C) 2013 Cyril Hrubis <metan(a)ucw.cz>
+ */
/*
* List of all known pixel types
*/
typedef enum GP_PixelType {
-%% for pt in pixeltypes
+@ for pt in pixeltypes:
GP_PIXEL_{{ pt.name }},
-%% endfor
+@ end
GP_PIXEL_MAX,
} GP_PixelType;
-%% for pt in pixeltypes
+@ for pt in pixeltypes:
#define GP_PIXEL_{{ pt.name }} GP_PIXEL_{{ pt.name }}
-%% endfor
+@ end
-%% for pt in pixeltypes
-%% if not pt.is_unknown()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown():
/* Automatically generated code for pixel type {{ pt.name }}
*
* Size (bpp): {{ pt.pixelsize.size }} ({{ pt.pixelsize.suffix }})
* Bit endian: {{ pt.pixelsize.bit_endian_const }}
- * Pixel structure: {{ pt.bits|join("") }}
+ * Pixel structure: {{ "".join(pt.bits) }}
* Channels:
-%% for c in pt.chanslist
+@ for c in pt.chanslist:
* {{ c[0] }} offset:{{ c[1] }} size:{{ c[2] }}
-%% endfor
+@ end
*/
/*
* macros to get channels of pixel type {{ pt.name }}
*/
-%% for c in pt.chanslist
+@ for c in pt.chanslist:
#define GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(p) (GP_GET_BITS({{ c[1] }}, {{ c[2] }}, (p)))
-%% endfor
+@ end
/*
* macros to get address and bit-offset of a pixel {{ pt.name }} in a context
@@ -74,32 +51,29 @@ typedef enum GP_PixelType {
* macros to create GP_Pixel of pixel type {{ pt.name }} directly from given values.
* The values MUST be already clipped/converted to relevant value ranges.
*/
-#define GP_Pixel_CREATE_{{ pt.name }}({{ pt.chanslist[0][0] }}{% for c in pt.chanslist[1:] %}, {{ c[0] }}{% endfor %}) (0-%% for c in pt.chanslist
+#define GP_Pixel_CREATE_{{ pt.name }}({{ ', '.join(pt.chan_names) }}) (0+@ for c in pt.chanslist:
+ (({{ c[0] }}) << {{ c[1] }}) -%% endfor
+@ end
)
-%% endif
-%% endfor
+@ end
/*
* macros for branching on PixelType (similar to GP_FnPerBpp macros)
*/
-%% for r in ['', 'return ']
-#define GP_FN_{% if r %}RET_{% endif %}PER_PIXELTYPE(FN_NAME, type, ...)+@ for r in [('', ''), ('return ', 'RET_')]:
+#define GP_FN_{{ r[1] }}PER_PIXELTYPE(FN_NAME, type, ...) switch (type) { -%% for pt in pixeltypes
-%% if not pt.is_unknown()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown():
case GP_PIXEL_{{ pt.name }}:- {{ r }}FN_NAME{{'##'}}_{{ pt.name }}(__VA_ARGS__);- break;-%% endif
-%% endfor
+ {{ r[0] }}FN_NAME{{'##'}}_{{ pt.name }}(__VA_ARGS__);+@ if not r[0]:
+ break;+@ end
+@ end
default: GP_ABORT("Invalid PixelType %d", type); }
-%% endfor
-
-%% endblock body
diff --git a/include/core/GP_WritePixel.gen.h.t b/include/core/GP_WritePixel.gen.h.t
index 015dc7c3..3e611f2d 100644
--- a/include/core/GP_WritePixel.gen.h.t
+++ b/include/core/GP_WritePixel.gen.h.t
@@ -1,30 +1,9 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends 'base.h.t'
-
-{% block descr %}Write Pixels generated header{% endblock %}
-
-{% block body %}
+@ include header.t
+/*
+ * Write Pixels generated header
+ *
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
/*
* These functions writes cnt pixels using value val starting at start address
@@ -32,15 +11,11 @@
* at off offset in the first byte (i.e. byte at the start address).
*/
-%% for ps in pixelsizes
-%% if ps.needs_bit_endian()
+@ for ps in pixelsizes:
+@ if ps.needs_bit_endian():
void GP_WritePixels_{{ ps.suffix }}(void *start, uint8_t off,
size_t cnt, unsigned int val);
-%% else
+@ else:
void GP_WritePixels_{{ ps.suffix }}(void *start, size_t cnt, unsigned int val);
-%% endif
-%% endfor
-
-{% endblock body %}
diff --git a/include/core/Makefile b/include/core/Makefile
index 6267d32f..fb723b95 100644
--- a/include/core/Makefile
+++ b/include/core/Makefile
@@ -7,5 +7,5 @@ GENHEADERS=GP_Convert_Scale.gen.h GP_Pixel.gen.h GP_MixPixels.gen.h GP_GammaCorrection.gen.h GP_GammaPixel.gen.h GP_WritePixel.gen.h GP_MixPixels2.gen.h
-include $(TOPDIR)/gen.mk
+include $(TOPDIR)/genn.mk
include $(TOPDIR)/post.mk
diff --git a/include/gfx/GP_HLine.gen.h.t b/include/gfx/GP_HLine.gen.h.t
index 8e696a7f..1ed91346 100644
--- a/include/gfx/GP_HLine.gen.h.t
+++ b/include/gfx/GP_HLine.gen.h.t
@@ -1,35 +1,11 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends 'base.h.t'
-
-{% block descr %}HLine generated header{% endblock %}
-
-{% block body %}
-
-%% for ps in pixelsizes
+@ include header.t
+/*
+ * HLine generated header
+ *
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
+
+@ for ps in pixelsizes:
void GP_HLine_Raw_{{ ps.suffix }}(GP_Context *context, GP_Coord x0,
GP_Coord x1, GP_Coord y, GP_Pixel pixel);
-%% endfor
-
-{% endblock body %}
diff --git a/include/gfx/GP_VLine.gen.h.t b/include/gfx/GP_VLine.gen.h.t
index 11a8702e..0261557d 100644
--- a/include/gfx/GP_VLine.gen.h.t
+++ b/include/gfx/GP_VLine.gen.h.t
@@ -1,35 +1,11 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends 'base.h.t'
-
-{% block descr %}VLine generated header{% endblock %}
-
-{% block body %}
-
-%% for ps in pixelsizes
+@ include header.t
+/*
+ * VLine generated header
+ *
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
+
+@ for ps in pixelsizes:
void GP_VLine_Raw_{{ ps.suffix }}(GP_Context *context, GP_Coord x,
GP_Coord y0, GP_Coord y1, GP_Pixel pixel);
-%% endfor
-
-{% endblock body %}
diff --git a/include/gfx/Makefile b/include/gfx/Makefile
index 894b8985..9f6929c7 100644
--- a/include/gfx/Makefile
+++ b/include/gfx/Makefile
@@ -4,5 +4,5 @@ include $(TOPDIR)/pre.mk
GENHEADERS=GP_VLine.gen.h GP_HLine.gen.h
-include $(TOPDIR)/gen.mk
+include $(TOPDIR)/genn.mk
include $(TOPDIR)/post.mk
diff --git a/libs/core/GP_Blit.gen.c.t b/libs/core/GP_Blit.gen.c.t
index b702e88c..c7f17388 100644
--- a/libs/core/GP_Blit.gen.c.t
+++ b/libs/core/GP_Blit.gen.c.t
@@ -1,31 +1,11 @@
-/*****************************************************************************
- * 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) 2011 Tomas Gavenciak <gavento(a)ucw.cz> *
- * Copyright (C) 2011-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.c.t"
-
-{% block descr %}Specialized blit functions and macros.{% endblock %}
+@ include source.t
+/*
+ * Specialized blit functions and macros.
+ *
+ * Copyright (C) 2011 Tomas Gavenciak <gavento(a)ucw.cz>
+ * Copyright (C) 2011-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
-%% block body
#include <string.h>
#include "core/GP_Pixel.h"
@@ -60,7 +40,7 @@ static void blitXYXY_Naive_Raw(const GP_Context *src,
}
}
-%% for ps in pixelsizes
+@ for ps in pixelsizes:
/*
* Blit for equal pixel types {{ ps.suffix }}
*/
@@ -68,7 +48,7 @@ static void blitXYXY_Raw_{{ ps.suffix }}(const GP_Context *src,
GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
GP_Context *dst, GP_Coord x2, GP_Coord y2)
{
-%% if not ps.needs_bit_endian()
+@ if not ps.needs_bit_endian():
/* memcpy() each horizontal line */
GP_Coord y;
@@ -76,8 +56,9 @@ static void blitXYXY_Raw_{{ ps.suffix }}(const GP_Context *src,
memcpy(GP_PIXEL_ADDR_{{ ps.suffix }}(dst, x2, y2 + y),
GP_PIXEL_ADDR_{{ ps.suffix }}(src, x0, y0 + y),
{{ int(ps.size/8) }} * (x1 - x0 + 1));
-%% else
-{# /* Rectangles may not be bit-aligned in the same way! */
+@ else:
+# if 0
+ /* Rectangles may not be bit-aligned in the same way! */
/* Alignment (index) of first bits in the first byte */
//TODO: This is wrong for subcontexts where the offset
// needs to be summed with context->offset and moduled
@@ -109,22 +90,21 @@ static void blitXYXY_Raw_{{ ps.suffix }}(const GP_Context *src,
end_p2 += dst->bytes_per_row;
}
} else /* Different bit-alignment, can't use memcpy() */
-#}
+#endif
blitXYXY_Naive_Raw(src, x0, y0, x1, y1, dst, x2, y2);
-%% endif
+@ end
}
-%% endfor
-
+@ end
/*
* Generate Blits, I know this is n^2 variants but the gain is in speed is
* more than 50% and the size footprint for two for cycles is really small.
*/
-%% for src in pixeltypes
-%% if not src.is_unknown() and not src.is_palette()
-%% for dst in pixeltypes
-%% if not dst.is_unknown() and not dst.is_palette()
-%% if dst.name != src.name
+@ for src in pixeltypes:
+@ if not src.is_unknown() and not src.is_palette():
+@ for dst in pixeltypes:
+@ if not dst.is_unknown() and not dst.is_palette():
+@ if dst.name != src.name:
/*
* Blits {{ src.name }} to {{ dst.name }}
*/
@@ -142,23 +122,19 @@ static void blitXYXY_Raw_{{ src.name }}_{{ dst.name }}(const GP_Context *src,
GP_Pixel p1, p2 = 0, p3 = 0;
p1 = GP_GetPixel_Raw_{{ src.pixelsize.suffix }}(src, x, y);
-%% if src.is_alpha()
+@ if src.is_alpha():
p2 = GP_GetPixel_Raw_{{ dst.pixelsize.suffix }}(dst, dx, dy);
p3 = GP_MixPixels_{{ src.name }}_{{ dst.name }}(p1, p2);
-%% else
+@ else:
GP_Pixel_{{ src.name }}_TO_RGB888(p1, p2);
GP_Pixel_RGB888_TO_{{ dst.name }}(p2, p3);
-%% endif
+@ end
GP_PutPixel_Raw_{{ dst.pixelsize.suffix }}(dst, dx, dy, p3);
}
}
}
-%% endif
-%% endif
-%% endfor
-%% endif
-%% endfor
+@ end
void GP_BlitXYXY_Raw_Fast(const GP_Context *src,
GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
@@ -173,26 +149,23 @@ void GP_BlitXYXY_Raw_Fast(const GP_Context *src,
/* Specialized functions */
switch (src->pixel_type) {
-%% for src in pixeltypes
-%% if not src.is_unknown() and not src.is_palette()
+@ for src in pixeltypes:
+@ if not src.is_unknown() and not src.is_palette():
case GP_PIXEL_{{ src.name }}:
switch (dst->pixel_type) {
-%% for dst in pixeltypes
-%% if not dst.is_unknown() and not dst.is_palette()
-%% if dst.name != src.name
+@ for dst in pixeltypes:
+@ if not dst.is_unknown() and not dst.is_palette():
+@ if dst.name != src.name:
case GP_PIXEL_{{ dst.name }}:
blitXYXY_Raw_{{ src.name }}_{{ dst.name }}(src, x0, y0, x1, y1, dst, x2, y2);
break;
-%% endif
-%% endif
-%% endfor
+@ end
default:
GP_ABORT("Invalid destination pixel %s",
GP_PixelTypeName(dst->pixel_type));
}
break;
-%% endif
-%% endfor
+@ end
default:
GP_ABORT("Invalid source pixel %s",
GP_PixelTypeName(src->pixel_type));
@@ -202,11 +175,11 @@ void GP_BlitXYXY_Raw_Fast(const GP_Context *src,
/*
* And the same for non-raw variants.
*/
-%% for src in pixeltypes
-%% if not src.is_unknown() and not src.is_palette()
-%% for dst in pixeltypes
-%% if not dst.is_unknown() and not dst.is_palette()
-%% if dst.name != src.name
+@ for src in pixeltypes:
+@ if not src.is_unknown() and not src.is_palette():
+@ for dst in pixeltypes:
+@ if not dst.is_unknown() and not dst.is_palette():
+@ if dst.name != src.name:
/*
* Blits {{ src.name }} to {{ dst.name }}
*/
@@ -231,16 +204,12 @@ static void blitXYXY_{{ src.name }}_{{ dst.name }}(const GP_Context *src,
}
}
-%% endif
-%% endif
-%% endfor
-%% endif
-%% endfor
+@ end
/*
* Same pixel type but with rotation.
*/
-%% for ps in pixelsizes
+@ for ps in pixelsizes:
/*
* Blits for same pixel type and bpp {{ ps.suffix }}
*/
@@ -262,7 +231,7 @@ static void blitXYXY_{{ ps.suffix }}(const GP_Context *src,
GP_PutPixel_Raw_{{ ps.suffix }}(dst, xt, yt, p);
}
}
-%% endfor
+@ end
void GP_BlitXYXY_Fast(const GP_Context *src,
GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
@@ -286,30 +255,25 @@ void GP_BlitXYXY_Fast(const GP_Context *src,
/* Specialized functions */
switch (src->pixel_type) {
-%% for src in pixeltypes
-%% if not src.is_unknown() and not src.is_palette()
+@ for src in pixeltypes:
+@ if not src.is_unknown() and not src.is_palette():
case GP_PIXEL_{{ src.name }}:
switch (dst->pixel_type) {
-%% for dst in pixeltypes
-%% if not dst.is_unknown() and not dst.is_palette()
-%% if dst.name != src.name
+@ for dst in pixeltypes:
+@ if not dst.is_unknown() and not dst.is_palette():
+@ if dst.name != src.name:
case GP_PIXEL_{{ dst.name }}:
blitXYXY_{{ src.name }}_{{ dst.name }}(src, x0, y0, x1, y1, dst, x2, y2);
break;
-%% endif
-%% endif
-%% endfor
+@ end
default:
GP_ABORT("Invalid destination pixel %s",
GP_PixelTypeName(dst->pixel_type));
}
break;
-%% endif
-%% endfor
+@ end
default:
GP_ABORT("Invalid source pixel %s",
GP_PixelTypeName(src->pixel_type));
}
}
-
-%% endblock body
diff --git a/libs/core/GP_Convert.gen.c.t b/libs/core/GP_Convert.gen.c.t
index ef004e44..674e04dc 100644
--- a/libs/core/GP_Convert.gen.c.t
+++ b/libs/core/GP_Convert.gen.c.t
@@ -1,90 +1,61 @@
-/*****************************************************************************
- * 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) 2011 Tomas Gavenciak <gavento(a)ucw.cz> *
- * Copyright (C) 2011 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.c.t"
-
-{% block descr %}Convert PixelType values macros and functions{% endblock %}
-
-%% block body
+@ include source.t
+/*
+ * Convert PixelType values macros and functions
+ *
+ * Copyright (C) 2011 Tomas Gavenciak <gavento(a)ucw.cz>
+ * Copyright (C) 2011-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include "GP_Convert.h"
-
-{#
- # Loop around pixel types central for the conversion.
--#}
-%% for pt in [pixeltypes_dict['RGB888'], pixeltypes_dict['RGBA8888']]
+@
+@ # Loop around pixel types central for the conversion.
+@ for pt in [pixeltypes_dict['RGB888'], pixeltypes_dict['RGBA8888']]:
GP_Pixel GP_{{ pt.name }}ToPixel(GP_Pixel pixel, GP_PixelType type)
{
GP_Pixel p = 0;
switch (type) {
-%% for tf in pixeltypes
-%% if tf.is_unknown()
+@ for tf in pixeltypes:
+@ if tf.is_unknown():
case GP_PIXEL_UNKNOWN:
GP_ABORT("Cannot convert {{ pt.name }} to GP_PIXEL_UNKNOWN");
break;
-%% elif tf.is_palette()
+@ elif tf.is_palette():
case GP_PIXEL_{{ tf.name }}:
GP_ABORT("Cannot convert {{ pt.name }} to palette type {{ tf.name }}");
break;
-%% else
+@ else:
case GP_PIXEL_{{ tf.name }}:
GP_Pixel_{{ pt.name }}_TO_{{ tf.name }}(pixel, p);
break;
-%% endif
-%% endfor
+@ end
default:
GP_ABORT("Unknown PixelType %ud", type);
}
return p;
}
-
GP_Pixel GP_PixelTo{{ pt.name }}(GP_Pixel pixel, GP_PixelType type)
{
GP_Pixel p = 0;
switch (type) {
-%% for sf in pixeltypes
-%% if sf.is_unknown()
+@ for sf in pixeltypes:
+@ if sf.is_unknown():
case GP_PIXEL_UNKNOWN:
GP_ABORT("Cannot convert from GP_PIXEL_UNKNOWN");
break;
-%% elif sf.is_palette()
+@ elif sf.is_palette():
case GP_PIXEL_{{ sf.name }}:
GP_ABORT("Cannot convert from palette type {{ sf.name }} (yet)");
break;
-%% else
+@ else:
case GP_PIXEL_{{ sf.name }}:
GP_Pixel_{{ sf.name }}_TO_{{ pt.name }}(pixel, p);
break;
-%% endif
-%% endfor
+@ end
default:
GP_ABORT("Unknown PixelType %u", type);
}
return p;
}
-%% endfor
-
-%% endblock body
diff --git a/libs/core/GP_Fill.gen.c.t b/libs/core/GP_Fill.gen.c.t
index f2c4b8d0..49f8edec 100644
--- a/libs/core/GP_Fill.gen.c.t
+++ b/libs/core/GP_Fill.gen.c.t
@@ -1,32 +1,10 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends 'base.c.t'
-
-{% block descr %}
-Optimized fill functions.
-{% endblock descr %}
-
-%% block body
+@ include source.t
+@ include WritePixels.t
+/*
+ * Optimized fill functions.
+ *
+ * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include "core/GP_Context.h"
#include "core/GP_WritePixel.h"
@@ -34,34 +12,30 @@ Optimized fill functions.
#include "core/GP_FnPerBpp.h"
#include "core/GP_Fill.h"
-%% from './WritePixels.t' import optimized_writepixels
-
-%% for ps in pixelsizes
+@ for ps in pixelsizes:
static void fill_{{ ps.suffix }}(GP_Context *ctx, GP_Pixel val)
{
unsigned int y;
for (y = 0; y < ctx->h; y++) {
-%% if ps.suffix in optimized_writepixels
+@ if ps.suffix in optimized_writepixels:
void *start = GP_PIXEL_ADDR(ctx, 0, y);
-%% if ps.needs_bit_endian()
+@ if ps.needs_bit_endian():
GP_WritePixels_{{ ps.suffix }}(start, 0, ctx->w, val);
-%% else
+@ else:
GP_WritePixels_{{ ps.suffix }}(start, ctx->w, val);
-%% endif
-%% else
+@ else:
unsigned int x;
for (x = 0; x < ctx->w; x++)
GP_PutPixel_Raw_{{ ps.suffix }}(ctx, x, y, val);
-%% endif
+@ end
}
}
-%% endfor
+@ end
void GP_Fill(GP_Context *ctx, GP_Pixel val)
{
GP_FN_PER_BPP_CONTEXT(fill, ctx, ctx, val);
}
-%% endblock body
diff --git a/libs/core/GP_GammaCorrection.gen.c.t b/libs/core/GP_GammaCorrection.gen.c.t
index 72883b28..18713dc6 100644
--- a/libs/core/GP_GammaCorrection.gen.c.t
+++ b/libs/core/GP_GammaCorrection.gen.c.t
@@ -1,35 +1,8 @@
-/*****************************************************************************
- * 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) 2012 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.c.t"
-
-{% block descr %}Gamma correction tables for Gamma = 2.2{% endblock %}
-
-%% block body
-
+@ include source.t
/*
- * Gamma correction tables.
+ * Gamma correction tables for Gamma = 2.2
*
- * Copyright (c) 2012 Cyril Hrubis <metan(a)ucw.cz>
+ * Copyright (C) 2012-2014 Cyril Hrubis <metan(a)ucw.cz>
*/
#include <stdint.h>
@@ -38,24 +11,22 @@
* Converts 8 bit gamma to 10 bit linear.
*/
static uint16_t gamma8_linear10[] = {
-%% for i in range(0, 256)
+@ for i in range(0, 256):
{{ int(((float(i)/255) ** 2.2) * 1024 + 0.5) }}, /* {{i}} */
-%% endfor
+@ end
};
/*
* Converts 10 bit linear to 8 bit gamma.
*/
static uint8_t linear10_gamma8[] = {
-%% for i in range(0, 1025)
+@ for i in range(0, 1025):
{{ int(((float(i)/1024) ** (1/2.2)) * 255 + 0.5) }}, /* {{i}} */
-%% endfor
+@ end
};
/*
* Pointers to tables
*/
uint16_t *GP_Gamma8_Linear10 = gamma8_linear10;
-uint8_t *GP_Linear10_Gamma8 = linear10_gamma8;
-
-%% endblock body
+uint8_t *GP_Linear10_Gamma8 = linear10_gamma8;
diff --git a/libs/core/GP_Pixel.gen.c.t b/libs/core/GP_Pixel.gen.c.t
index 302655f4..8a13a568 100644
--- a/libs/core/GP_Pixel.gen.c.t
+++ b/libs/core/GP_Pixel.gen.c.t
@@ -1,79 +1,68 @@
-/*****************************************************************************
- * 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) 2011-2012 Tomas Gavenciak <gavento(a)ucw.cz> *
- * Copyright (C) 2011-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.c.t"
-
-%% block descr
-Pixel type definitions and functions
-%% endblock
+@ include source.t
+/*
+ * Pixel type definitions and functions
+ *
+ * Copyright (C) 2011-2012 Tomas Gavenciak <gavento(a)ucw.cz>
+ * Copyright (C) 2011-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
-%% block body
#include <stdio.h>
#include "GP_Pixel.h"
#include "GP_GetSetBits.h"
-
-%%- macro getflags(pt)
-{% if pt.is_alpha() %} | GP_PIXEL_HAS_ALPHA{% endif -%}
-{% if pt.is_rgb() %} | GP_PIXEL_IS_RGB{% endif -%}
-{% if pt.is_palette() %} | GP_PIXEL_IS_PALETTE{% endif -%}
-{% if pt.is_gray() %} | GP_PIXEL_IS_GRAYSCALE{% endif -%}
-{% if pt.is_cmyk() %} | GP_PIXEL_IS_CMYK{% endif -%}
-%%- endmacro
+@
+@ def getflags(pt):
+@ flags = []
+@ if pt.is_alpha():
+@ flags.append('GP_PIXEL_HAS_ALPHA')
+@ if pt.is_rgb():
+@ flags.append('GP_PIXEL_IS_RGB')
+@ if pt.is_palette():
+@ flags.append('GP_PIXEL_IS_PALETTE')
+@ if pt.is_gray():
+@ flags.append('GP_PIXEL_IS_GRAYSCALE')
+@ if pt.is_cmyk():
+@ flags.append('GP_PIXEL_IS_CMYK')
+@ if flags:
+@ return ' | '.join(flags)
+@ else:
+@ return 0
+@ end
/*
* Description of all known pixel types
*/
const GP_PixelTypeDescription GP_PixelTypes [GP_PIXEL_MAX] = {
-%% for pt in pixeltypes
+@ for pt in pixeltypes:
/* GP_PIXEL_{{ pt.name }} */ {
.type = GP_PIXEL_{{ pt.name }},
.name = "{{ pt.name }}",
.size = {{ pt.pixelsize.size }},
.bit_endian = {{ pt.pixelsize.bit_endian_const }},
.numchannels = {{ len(pt.chanslist) }},
- .bitmap = "{{ pt.bits|join("") }}",
- .flags = 0{{ getflags(pt) }},
+ .bitmap = "{{ ''.join(pt.bits) }}",
+ .flags = {{ getflags(pt) }},
.channels = {
-%% for c in pt.chanslist
+@ for c in pt.chanslist:
{ .name = "{{ c[0] }}", .offset = {{ c[1] }}, .size = {{ c[2] }} },
-%% endfor
- } },
-%% endfor
+@ end
+ }
+ },
+@ end
};
-%% for pt in pixeltypes
-%% if not pt.is_unknown()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown():
/*
* snprintf a human readable value of pixel type {{pt.name}}
*/
static void GP_PixelSNPrint_{{ pt.name }}(char *buf, size_t len, GP_Pixel p)
{
- snprintf(buf, len, "{{ pt.name }} 0x%0{{ (pt.pixelsize.size+3)//4 }}x{% for c in pt.chanslist %} {{ c[0] }}=%d{% endfor %}",
- GP_GET_BITS(0, {{ pt.pixelsize.size }}, p){% for c in pt.chanslist %}, GP_Pixel_GET_{{ c.name}}_{{ pt.name }}(p){% endfor %});
+ snprintf(buf, len, "{{ pt.name }} 0x%0{{ (pt.pixelsize.size+3)//4 }}x {{ '=%d '.join(pt.chan_names) + '=%d' }}",
+ GP_GET_BITS(0, {{ pt.pixelsize.size }}, p),
+ {{ arr_to_params(pt.chan_names, 'GP_Pixel_GET_', '_' + pt.name + '(p)') }});
}
-%% endif
-%% endfor
+@ end
void GP_PixelSNPrint(char *buf, size_t len, GP_Pixel p, GP_PixelType pixel_type)
{
@@ -86,5 +75,3 @@ void GP_PixelPrint(GP_Pixel p, GP_PixelType pixel_type)
GP_PixelSNPrint(buf, sizeof(buf), p, pixel_type);
puts(buf);
}
-
-%% endblock body
diff --git a/libs/core/Makefile b/libs/core/Makefile
index 37e61703..2e98fee3 100644
--- a/libs/core/Makefile
+++ b/libs/core/Makefile
@@ -7,6 +7,6 @@ GENSOURCES=GP_Pixel.gen.c GP_Blit.gen.c GP_Convert.gen.c CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c))
LIBNAME=core
-include $(TOPDIR)/gen.mk
+include $(TOPDIR)/genn.mk
include $(TOPDIR)/lib.mk
include $(TOPDIR)/post.mk
diff --git a/libs/core/WritePixels.t b/libs/core/WritePixels.t
index ef8ba94f..06a9895f 100644
--- a/libs/core/WritePixels.t
+++ b/libs/core/WritePixels.t
@@ -1,30 +1,7 @@
-/*****************************************************************************
- * 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> *
- * *
- *****************************************************************************/
-
-{# Explicit list of BPP that have optimized write pixel #}
-%% set optimized_writepixels = ['1BPP_LE', '1BPP_BE',
- '2BPP_LE', '2BPP_BE',
- '4BPP_LE', '4BPP_BE',
- '8BPP',
- '16BPP',
- '24BPP',
- '32BPP']
+@ optimized_writepixels = ['1BPP_LE', '1BPP_BE',
+@ '2BPP_LE', '2BPP_BE',
+@ '4BPP_LE', '4BPP_BE',
+@ '8BPP',
+@ '16BPP',
+@ '24BPP',
+@ '32BPP']
diff --git a/libs/filters/GP_ApplyTables.gen.c.t b/libs/filters/GP_ApplyTables.gen.c.t
index f166af3a..dd3581cf 100644
--- a/libs/filters/GP_ApplyTables.gen.c.t
+++ b/libs/filters/GP_ApplyTables.gen.c.t
@@ -1,32 +1,9 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "filter.c.t"
-
-%% block descr
-Generic Point filer
-%% endblock
-
-%% block body
+@ include source.t
+/*
+ * Generic Point filer
+ *
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include <errno.h>
@@ -36,8 +13,8 @@ Generic Point filer
#include "filters/GP_ApplyTables.h"
-%% for pt in pixeltypes
-%% if not pt.is_unknown() and not pt.is_palette()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown() and not pt.is_palette():
static int apply_tables_{{ pt.name }}(const GP_Context *const src,
GP_Coord x_src, GP_Coord y_src,
GP_Size w_src, GP_Size h_src,
@@ -50,9 +27,9 @@ static int apply_tables_{{ pt.name }}(const GP_Context *const src,
unsigned int x, y;
-%% for c in pt.chanslist
+@ for c in pt.chanslist:
GP_Pixel {{ c.name }};
-%% endfor
+@ end
for (y = 0; y < h_src; y++) {
for (x = 0; x < w_src; x++) {
@@ -63,12 +40,12 @@ static int apply_tables_{{ pt.name }}(const GP_Context *const src,
GP_Pixel pix = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(src, src_x, src_y);
-%% for c in pt.chanslist
+@ for c in pt.chanslist:
{{ c.name }} = GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix);
{{ c.name }} = tables->table[{{ c.idx }}][{{ c.name }}];
-%% endfor
+@ end
- pix = GP_Pixel_CREATE_{{ pt.name }}({{ expand_chanslist(pt, "", "") }});
+ pix = GP_Pixel_CREATE_{{ pt.name }}({{ arr_to_params(pt.chan_names) }});
GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(dst, dst_x, dst_y, pix);
}
@@ -83,9 +60,8 @@ static int apply_tables_{{ pt.name }}(const GP_Context *const src,
return 0;
}
-%% endif
-%% endfor
-
+@ end
+@
int GP_FilterTablesApply(const GP_Context *const src,
GP_Coord x_src, GP_Coord y_src,
GP_Size w_src, GP_Size h_src,
@@ -98,20 +74,17 @@ int GP_FilterTablesApply(const GP_Context *const src,
//TODO: Assert size
switch (src->pixel_type) {
-%% for pt in pixeltypes
-%% if not pt.is_unknown() and not pt.is_palette()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown() and not pt.is_palette():
case GP_PIXEL_{{ pt.name }}:
return apply_tables_{{ pt.name }}(src, x_src, y_src,
w_src, h_src, dst,
x_dst, y_dst,
tables, callback);
break;
-%% endif
-%% endfor
+@ end
default:
errno = EINVAL;
return -1;
}
}
-
-%% endblock body
diff --git a/libs/filters/GP_Cubic.gen.c.t b/libs/filters/GP_Cubic.gen.c.t
index e5f5cf43..c9590628 100644
--- a/libs/filters/GP_Cubic.gen.c.t
+++ b/libs/filters/GP_Cubic.gen.c.t
@@ -1,49 +1,19 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.c.t"
-
-{% block descr %}Table for fixed point cubic coeficients for A=0.5{% endblock %}
-
-%% block body
-
+@ include source.t
/*
- * Fixed point cubic coeficients.
+ * Table for fixed point cubic coeficients for A=0.5
*
- * Copyright (c) 2012 Cyril Hrubis <metan(a)ucw.cz>
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
*/
#include <stdint.h>
int16_t GP_CubicTable[2047] = {
-%% set A=0.5
-%% for i in range(0, 1023)
-%% set x = i/1024
- {{ round(((2 - A)*x*x*x + (A - 3)*x*x + 1) * 1024) }}, /* {{ i }} {{ x }} */
-%% endfor
-%% for i in range(1024, 2047)
-%% set x = i/1024
- {{ round((-A*x*x*x + 5*A*x*x - 8*A*x + 4*A) * 1024) }}, /* {{ i }} {{ x }} */
-%% endfor
+@ A=0.5
+@ for i in range(0, 1023):
+@ x = i/1024
+ {{ round(((2 - A)*x*x*x + (A - 3)*x*x + 1) * 1024) }}, /* {{ '%-4i %.6f' % (i, x) }} */
+@ for i in range(1024, 2047):
+@ x = i/1024
+ {{ round((-A*x*x*x + 5*A*x*x - 8*A*x + 4*A) * 1024) }}, /* {{ '%-4i %.6f' % (i, x) }} */
+@ end
};
-
-%% endblock body
diff --git a/libs/filters/GP_FloydSteinberg.gen.c.t b/libs/filters/GP_FloydSteinberg.gen.c.t
index f63c8cce..77492b1e 100644
--- a/libs/filters/GP_FloydSteinberg.gen.c.t
+++ b/libs/filters/GP_FloydSteinberg.gen.c.t
@@ -1,54 +1,33 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "common.c.t"
-
-{% block descr %}Floyd Steinberg dithering RGB888 -> any pixel{% endblock %}
-
-%% block body
-
+@ include source.t
+/*
+ * Floyd Steinberg dithering RGB888 -> any pixel
+ *
+ * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include <string.h>
#include <errno.h>
#include "core/GP_Core.h"
#include "core/GP_Pixel.h"
+#include "core/GP_Clamp.h"
#include "filters/GP_Filter.h"
#include "filters/GP_Dither.h"
-%% macro distribute_error(errors, x, y, w, err)
- if ({{ x }} + 1 < {{ w }})
- {{ errors }}[{{ y }}%2][{{ x }}+1] += 7 * {{ err }} / 16;
+@ def distribute_error(errors, x, y, w, err):
+if ({{ x }} + 1 < {{ w }})
+ {{ errors }}[{{ y }}%2][{{ x }}+1] += 7 * {{ err }} / 16;
- if ({{ x }} > 1)
- {{ errors }}[!({{ y }}%2)][{{ x }}-1] += 3 * {{ err }} / 16;
+if ({{ x }} > 1)
+ {{ errors }}[!({{ y }}%2)][{{ x }}-1] += 3 * {{ err }} / 16;
- {{ errors }}[!({{ y }}%2)][{{ x }}] += 5 * {{ err }} / 16;
+{{ errors }}[!({{ y }}%2)][{{ x }}] += 5 * {{ err }} / 16;
- if ({{ x }} + 1 < {{ w }})
- {{ errors }}[!({{ y }}%2)][{{ x }}+1] += {{ err }} / 16;
-%% endmacro
-
-%% for pt in pixeltypes
-%% if pt.is_gray() or pt.is_rgb() and not pt.is_alpha()
+if ({{ x }} + 1 < {{ w }})
+ {{ errors }}[!({{ y }}%2)][{{ x }}+1] += {{ err }} / 16;
+@ end
+@
+@ for pt in pixeltypes:
+@ if pt.is_gray() or pt.is_rgb() and not pt.is_alpha():
/*
* Floyd Steinberg to {{ pt.name }}
*/
@@ -56,9 +35,9 @@ static int floyd_steinberg_to_{{ pt.name }}_Raw(const GP_Context *src,
GP_Context *dst,
GP_ProgressCallback *callback)
{
-%% for c in pt.chanslist
- float errors_{{ c[0] }}[2][src->w];
-%% endfor
+@ for c in pt.chanslist:
+ float errors_{{ c.name }}[2][src->w];
+@ end
GP_DEBUG(1, "Floyd Steinberg %s to %s %ux%u",
GP_PixelTypeName(src->pixel_type),
@@ -67,10 +46,10 @@ static int floyd_steinberg_to_{{ pt.name }}_Raw(const GP_Context *src,
GP_Coord x, y;
-%% for c in pt.chanslist
- memset(errors_{{ c[0] }}[0], 0, src->w * sizeof(float));
- memset(errors_{{ c[0] }}[1], 0, src->w * sizeof(float));
-%% endfor
+@ for c in pt.chanslist:
+ memset(errors_{{ c.name }}[0], 0, src->w * sizeof(float));
+ memset(errors_{{ c.name }}[1], 0, src->w * sizeof(float));
+@ end
for (y = 0; y < (GP_Coord)src->h; y++) {
for (x = 0; x < (GP_Coord)src->w; x++) {
@@ -79,42 +58,42 @@ static int floyd_steinberg_to_{{ pt.name }}_Raw(const GP_Context *src,
pix = GP_GetPixel_Raw(src, x, y);
pix = GP_PixelToRGB888(pix, src->pixel_type);
-%% for c in pt.chanslist
-%% if pt.is_gray()
- float val_{{ c[0] }} = GP_Pixel_GET_R_RGB888(pix) +
+@ for c in pt.chanslist:
+@ if pt.is_gray():
+ float val_{{ c.name }} = GP_Pixel_GET_R_RGB888(pix) +
GP_Pixel_GET_G_RGB888(pix) +
GP_Pixel_GET_B_RGB888(pix);
-%% else
- float val_{{ c[0] }} = GP_Pixel_GET_{{ c[0] }}_RGB888(pix);
-%% endif
- val_{{ c[0] }} += errors_{{ c[0] }}[y%2][x];
-
- float err_{{ c[0] }} = val_{{ c[0] }};
-%% if pt.is_gray()
- GP_Pixel res_{{ c[0] }} = {{ 2 ** c[2] - 1}} * val_{{ c[0] }} / (3 * 255);
- err_{{ c[0] }} -= res_{{ c[0] }} * (3 * 255) / {{ 2 ** c[2] - 1}};
-%% else
- GP_Pixel res_{{ c[0] }} = {{ 2 ** c[2] - 1}} * val_{{ c[0] }} / 255;
- err_{{ c[0] }} -= res_{{ c[0] }} * 255 / {{ 2 ** c[2] - 1}};
-%% endif
-
-{{ distribute_error("errors_%s"|format(c[0]), 'x', 'y', '(GP_Coord)src->w', 'err_%s'|format(c[0])) }}
-
- {{ clamp_val("res_%s"|format(c[0]), c[2]) }}
-%% endfor
-
-%% if pt.is_gray()
+@ else:
+ float val_{{ c.name }} = GP_Pixel_GET_{{ c.name }}_RGB888(pix);
+@ end
+ val_{{ c.name }} += errors_{{ c.name }}[y%2][x];
+
+ float err_{{ c.name }} = val_{{ c.name }};
+@ if pt.is_gray():
+ GP_Pixel res_{{ c.name }} = {{ 2 ** c[2] - 1}} * val_{{ c.name }} / (3 * 255);
+ err_{{ c.name }} -= res_{{ c.name }} * (3 * 255) / {{ 2 ** c[2] - 1}};
+@ else:
+ GP_Pixel res_{{ c.name }} = {{ 2 ** c[2] - 1}} * val_{{ c.name }} / 255;
+ err_{{ c.name }} -= res_{{ c.name }} * 255 / {{ 2 ** c[2] - 1}};
+@ end
+
+ {@ distribute_error('errors_' + c.name, 'x', 'y', '(GP_Coord)src->w', 'err_' + c.name) @}
+
+ GP_CLAMP_DOWN({{ 'res_' + c.name }}, {{ c.max }});
+@ end
+
+@ if pt.is_gray():
GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(dst, x, y, res_V);
-%% else
- GP_Pixel res = GP_Pixel_CREATE_{{ pt.name }}(res_{{ pt.chanslist[0][0] }}{% for c in pt.chanslist[1:] %}, res_{{ c[0] }}{% endfor %});
+@ else:
+ GP_Pixel res = GP_Pixel_CREATE_{{ pt.name }}({{ arr_to_params(pt.chan_names, 'res_') }});
GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(dst, x, y, res);
-%% endif
+@ end
}
-%% for c in pt.chanslist
- memset(errors_{{ c[0] }}[y%2], 0, src->w * sizeof(float));
-%% endfor
+@ for c in pt.chanslist:
+ memset(errors_{{ c.name }}[y%2], 0, src->w * sizeof(float));
+@ end
if (GP_ProgressCallbackReport(callback, y, src->h, src->w))
return 1;
@@ -124,9 +103,8 @@ static int floyd_steinberg_to_{{ pt.name }}_Raw(const GP_Context *src,
return 0;
}
-%% endif
-%% endfor
-
+@ end
+@
static int floyd_steinberg(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
@@ -138,12 +116,11 @@ static int floyd_steinberg(const GP_Context *src, GP_Context *dst,
}
switch (dst->pixel_type) {
-%% for pt in pixeltypes
-%% if pt.is_gray() or pt.is_rgb() and not pt.is_alpha()
+@ for pt in pixeltypes:
+@ if pt.is_gray() or pt.is_rgb() and not pt.is_alpha():
case GP_PIXEL_{{ pt.name }}:
return floyd_steinberg_to_{{ pt.name }}_Raw(src, dst, callback);
-%% endif
-%% endfor
+@ end
default:
errno = EINVAL;
return 1;
@@ -178,5 +155,3 @@ GP_Context *GP_FilterFloydSteinbergAlloc(const GP_Context *src,
return ret;
}
-
-%% endblock body
diff --git a/libs/filters/GP_GaussianNoise.gen.c.t b/libs/filters/GP_GaussianNoise.gen.c.t
index 939533b4..a8c6ad85 100644
--- a/libs/filters/GP_GaussianNoise.gen.c.t
+++ b/libs/filters/GP_GaussianNoise.gen.c.t
@@ -1,30 +1,9 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "filter.c.t"
-
-{% block descr %}Gaussian Noise{% endblock %}
-
-%% block body
+@ include source.t
+/*
+ * Gaussian Noise
+ *
+ * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include <errno.h>
@@ -38,8 +17,8 @@
#include "GP_Rand.h"
#include "GP_GaussianNoise.h"
-%% for pt in pixeltypes
-%% if not pt.is_unknown() and not pt.is_palette()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown() and not pt.is_palette():
static int GP_FilterGaussianNoiseAdd_{{ pt.name }}_Raw(const GP_Context *src,
GP_Coord x_src, GP_Coord y_src,
GP_Size w_src, GP_Size h_src,
@@ -51,37 +30,37 @@ static int GP_FilterGaussianNoiseAdd_{{ pt.name }}_Raw(const GP_Context *src,
GP_DEBUG(1, "Additive Gaussian noise filter %ux%u sigma=%f mu=%f",
w_src, h_src, sigma, mu);
- %% for c in pt.chanslist
- int sigma_{{ c[0] }} = {{ 2 ** c[2] - 1 }} * sigma;
- int mu_{{ c[0] }} = {{ 2 ** c[2] - 1 }} * mu;
- %% endfor
+@ for c in pt.chanslist:
+ int sigma_{{ c.name }} = {{ c.max }} * sigma;
+ int mu_{{ c.name }} = {{ c.max }} * mu;
+@ end
unsigned int size = w_src + w_src%2;
/* Create temporary buffers */
GP_TempAllocCreate(temp, sizeof(int) * size * {{ len(pt.chanslist) }});
- %% for c in pt.chanslist
- int *{{ c[0] }} = GP_TempAllocGet(temp, size * sizeof(int));
- %% endfor
+@ for c in pt.chanslist:
+ int *{{ c.name }} = GP_TempAllocGet(temp, size * sizeof(int));
+@ end
/* Apply the additive noise filter */
unsigned int x, y;
for (y = 0; y < h_src; y++) {
- %% for c in pt.chanslist
- GP_NormInt({{ c[0] }}, size, sigma_{{ c[0] }}, mu_{{ c[0] }});
- %% endfor
+@ for c in pt.chanslist:
+ GP_NormInt({{ c.name }}, size, sigma_{{ c.name }}, mu_{{ c.name }});
+@ end
for (x = 0; x < w_src; x++) {
GP_Pixel pix = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(src, x + x_src, y + y_src);
- %% for c in pt.chanslist
- {{ c[0] }}[x] += GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix);
- {{ c[0] }}[x] = GP_CLAMP({{ c[0] }}[x], 0, {{ 2 ** c[2] - 1 }});
- %% endfor
+@ for c in pt.chanslist:
+ {{ c.name }}[x] += GP_Pixel_GET_{{ c.name }}_{{ pt.name }}(pix);
+ {{ c.name }}[x] = GP_CLAMP({{ c.name }}[x], 0, {{ c.max }});
+@ end
- pix = GP_Pixel_CREATE_{{ pt.name }}({{ expand_chanslist(pt, "", "[x]") }});
+ pix = GP_Pixel_CREATE_{{ pt.name }}({{ arr_to_params(pt.chan_names, '', '[x]') }});
GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(dst, x + x_dst, y + y_dst, pix);
}
@@ -98,9 +77,8 @@ static int GP_FilterGaussianNoiseAdd_{{ pt.name }}_Raw(const GP_Context *src,
return 0;
}
-%% endif
-%% endfor
-
+@ end
+@
int GP_FilterGaussianNoiseAdd_Raw(const GP_Context *src,
GP_Coord x_src, GP_Coord y_src,
GP_Size w_src, GP_Size h_src,
@@ -110,15 +88,14 @@ int GP_FilterGaussianNoiseAdd_Raw(const GP_Context *src,
GP_ProgressCallback *callback)
{
switch (src->pixel_type) {
- %% for pt in pixeltypes
- %% if not pt.is_unknown() and not pt.is_palette()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown() and not pt.is_palette():
case GP_PIXEL_{{ pt.name }}:
return GP_FilterGaussianNoiseAdd_{{ pt.name }}_Raw(src, x_src,
y_src, w_src, h_src, dst, x_dst, y_dst,
sigma, mu, callback);
break;
- %% endif
- %% endfor
+@ end
default:
errno = EINVAL;
return -1;
@@ -173,5 +150,3 @@ GP_Context *GP_FilterGaussianNoiseAddExAlloc(const GP_Context *src,
return dst;
}
-
-%% endblock body
diff --git a/libs/filters/GP_HilbertPeano.gen.c.t b/libs/filters/GP_HilbertPeano.gen.c.t
index 1c11973c..e1a07f7b 100644
--- a/libs/filters/GP_HilbertPeano.gen.c.t
+++ b/libs/filters/GP_HilbertPeano.gen.c.t
@@ -1,30 +1,9 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.c.t"
-
-{% block descr %}Hilbert Peano dithering RGB888 -> any pixel{% endblock %}
-
-%% block body
+@ include source.t
+/*
+ * Hilbert Peano dithering RGB888 -> any pixel
+ *
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include <errno.h>
@@ -51,8 +30,8 @@ static unsigned int count_bits(unsigned int n)
return (i + (s != (1U<<i)));
}
-%% for pt in pixeltypes
-%% if pt.is_gray() or pt.is_rgb() and not pt.is_alpha()
+@ for pt in pixeltypes:
+@ if pt.is_gray() or pt.is_rgb() and not pt.is_alpha():
/*
* Hilbert Peano to {{ pt.name }}
*/
@@ -73,9 +52,9 @@ static int hilbert_peano_to_{{ pt.name }}_Raw(const GP_Context *src,
unsigned int cnt = 0;
/* error counters */
-%% for c in pt.chanslist
+@ for c in pt.chanslist:
int err_{{ c[0] }} = 0;
-%% endfor
+@ end
while (GP_HilbertCurveContinues(&state)) {
if (state.x < src->w && state.y < src->h) {
@@ -84,33 +63,31 @@ static int hilbert_peano_to_{{ pt.name }}_Raw(const GP_Context *src,
pix = GP_GetPixel_Raw(src, state.x, state.y);
pix = GP_PixelToRGB888(pix, src->pixel_type);
-%% for c in pt.chanslist
-%% if pt.is_gray()
+@ for c in pt.chanslist:
+@ if pt.is_gray():
int pix_{{ c[0] }} = GP_Pixel_GET_R_RGB888(pix) +
GP_Pixel_GET_G_RGB888(pix) +
GP_Pixel_GET_B_RGB888(pix);
-%% else
+@ else:
int pix_{{ c[0] }} = GP_Pixel_GET_{{ c[0] }}_RGB888(pix);
-%% endif
-
+@ end
pix_{{ c[0] }} += err_{{ c[0] }};
-%% if pt.is_gray()
+@ if pt.is_gray():
int res_{{ c[0] }} = ({{ 2 ** c[2] - 1}} * pix_{{ c[0] }} + 382) / {{ 3 * 255 }};
err_{{ c[0] }} = pix_{{ c[0] }} - {{ 3 * 255 }} * res_{{ c[0] }} / {{ 2 ** c[2] - 1 }};
-%% else
+@ else:
int res_{{ c[0] }} = ({{ 2 ** c[2] - 1}} * pix_{{ c[0] }} + 127) / 255;
err_{{ c[0] }} = pix_{{ c[0] }} - 255 * res_{{ c[0] }} / {{ 2 ** c[2] - 1 }};
-%% endif
-%% endfor
+@ end
-%% if pt.is_gray()
+@ if pt.is_gray():
GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(dst, state.x, state.y, res_V);
-%% else
- GP_Pixel res = GP_Pixel_CREATE_{{ pt.name }}(res_{{ pt.chanslist[0][0] }}{% for c in pt.chanslist[1:] %}, res_{{ c[0] }}{% endfor %});
+@ else:
+ GP_Pixel res = GP_Pixel_CREATE_{{ pt.name }}({{ arr_to_params(pt.chan_names, 'res_') }});
GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(dst, state.x, state.y, res);
-%% endif
+@ end
cnt++;
if (GP_ProgressCallbackReport(callback, cnt/src->h, src->w, src->h))
@@ -122,9 +99,9 @@ static int hilbert_peano_to_{{ pt.name }}_Raw(const GP_Context *src,
return 0;
}
} else {
-%% for c in pt.chanslist
+@ for c in pt.chanslist:
err_{{ c[0] }} = 0;
-%% endfor
+@ end
}
GP_HilbertCurveNext(&state);
@@ -134,9 +111,8 @@ static int hilbert_peano_to_{{ pt.name }}_Raw(const GP_Context *src,
return 0;
}
-%% endif
-%% endfor
-
+@ end
+@
static int hilbert_peano(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
@@ -148,12 +124,11 @@ static int hilbert_peano(const GP_Context *src, GP_Context *dst,
}
switch (dst->pixel_type) {
-%% for pt in pixeltypes
-%% if pt.is_gray() or pt.is_rgb() and not pt.is_alpha()
+@ for pt in pixeltypes:
+@ if pt.is_gray() or pt.is_rgb() and not pt.is_alpha():
case GP_PIXEL_{{ pt.name }}:
return hilbert_peano_to_{{ pt.name }}_Raw(src, dst, callback);
-%% endif
-%% endfor
+@ end
default:
errno = EINVAL;
return 1;
@@ -187,5 +162,3 @@ GP_Context *GP_FilterHilbertPeanoAlloc(const GP_Context *src,
return ret;
}
-
-%% endblock body
diff --git a/libs/filters/GP_LinearConvolution.gen.c.t b/libs/filters/GP_LinearConvolution.gen.c.t
index 70fe090f..4c320e18 100644
--- a/libs/filters/GP_LinearConvolution.gen.c.t
+++ b/libs/filters/GP_LinearConvolution.gen.c.t
@@ -1,30 +1,9 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "filter.c.t"
-
-{% block descr %}Linear Convolution{% endblock %}
-
-%% block body
+@ include source.t
+/*
+ * Linear Convolution
+ *
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include <errno.h>
@@ -38,8 +17,8 @@
#define MUL 1024
-%% for pt in pixeltypes
-%% if not pt.is_unknown() and not pt.is_palette()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown() and not pt.is_palette():
static int h_lin_conv_{{ pt.name }}(const GP_Context *src,
GP_Coord x_src, GP_Coord y_src,
@@ -62,9 +41,9 @@ static int h_lin_conv_{{ pt.name }}(const GP_Context *src,
/* Create temporary buffers */
GP_TempAllocCreate(temp, {{ len(pt.chanslist) }} * size * sizeof(int));
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
int *{{ c.name }} = GP_TempAllocGet(temp, size * sizeof(int));
- %% endfor
+@ end
/* Do horizontal linear convolution */
for (y = 0; y < (GP_Coord)h_src; y++) {
@@ -78,9 +57,9 @@ static int h_lin_conv_{{ pt.name }}(const GP_Context *src,
/* Copy border pixel until the source image starts */
while (xi <= 0 && i < size) {
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
{{ c.name }}[i] = GP_Pixel_GET_{{ c.name }}_{{ pt.name }}(pix);
- %% endfor
+@ end
i++;
xi++;
}
@@ -89,9 +68,9 @@ static int h_lin_conv_{{ pt.name }}(const GP_Context *src,
while (xi < (int)src->w && i < size) {
pix = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(src, xi, yi);
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
{{ c.name }}[i] = GP_Pixel_GET_{{ c.name }}_{{ pt.name }}(pix);
- %% endfor
+@ end
i++;
xi++;
@@ -99,39 +78,38 @@ static int h_lin_conv_{{ pt.name }}(const GP_Context *src,
/* Copy the rest the border pixel when we are out again */
while (i < size) {
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
{{ c.name }}[i] = GP_Pixel_GET_{{ c.name }}_{{ pt.name }}(pix);
- %% endfor
+@ end
i++;
}
for (x = 0; x < (GP_Coord)w_src; x++) {
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
int32_t {{ c.name }}_sum = MUL/2;
int *p{{ c.name }} = {{ c.name }} + x;
- %% endfor
+@ end
/* count the pixel value from neighbours weighted by kernel */
for (i = 0; i < kw; i++) {
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
{{ c.name }}_sum += (*p{{ c.name }}++) * ikernel[i];
- %% endfor
+@ end
}
/* divide the result */
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
{{ c.name }}_sum /= ikern_div;
- %% endfor
+@ end
/* and clamp just to be extra sure */
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
{{ c.name }}_sum = GP_CLAMP({{ c.name }}_sum, 0, {{ c.max }});
- %% endfor
-
+@ end
GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(dst, x_dst + x, y_dst + y,
GP_Pixel_CREATE_{{ pt.name }}(
- {{ expand_chanslist(pt, "", "_sum") }}
+ {{ arr_to_params(pt.chan_names, "", "_sum") }}
));
}
@@ -147,9 +125,7 @@ static int h_lin_conv_{{ pt.name }}(const GP_Context *src,
return 0;
}
-%% endif
-%% endfor
-
+@ end
int GP_FilterHLinearConvolution_Raw(const GP_Context *src,
GP_Coord x_src, GP_Coord y_src,
@@ -164,23 +140,22 @@ int GP_FilterHLinearConvolution_Raw(const GP_Context *src,
kw, x_src, y_src, w_src, h_src);
switch (src->pixel_type) {
- %% for pt in pixeltypes
- %% if not pt.is_unknown() and not pt.is_palette()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown() and not pt.is_palette():
case GP_PIXEL_{{ pt.name }}:
return h_lin_conv_{{ pt.name }}(src, x_src, y_src, w_src, h_src,
dst, x_dst, y_dst,
kernel, kw, kern_div, callback);
break;
- %% endif
- %% endfor
+@ end
default:
errno = EINVAL;
return -1;
}
}
-%% for pt in pixeltypes
-%% if not pt.is_unknown() and not pt.is_palette()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown() and not pt.is_palette():
static int v_lin_conv_{{ pt.name }}(const GP_Context *src,
GP_Coord x_src, GP_Coord y_src,
@@ -203,9 +178,9 @@ static int v_lin_conv_{{ pt.name }}(const GP_Context *src,
/* Create temporary buffers */
GP_TempAllocCreate(temp, {{ len(pt.chanslist) }} * size * sizeof(int));
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
int *{{ c.name }} = GP_TempAllocGet(temp, size * sizeof(int));
- %% endfor
+@ end
/* Do vertical linear convolution */
for (x = 0; x < (GP_Coord)w_src; x++) {
@@ -219,9 +194,9 @@ static int v_lin_conv_{{ pt.name }}(const GP_Context *src,
/* Copy border pixel until the source image starts */
while (yi <= 0 && i < size) {
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
{{ c.name }}[i] = GP_Pixel_GET_{{ c.name }}_{{ pt.name }}(pix);
- %% endfor
+@ end
i++;
yi++;
@@ -231,9 +206,9 @@ static int v_lin_conv_{{ pt.name }}(const GP_Context *src,
while (yi < (int)src->h && i < size) {
pix = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(src, xi, yi);
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
{{ c.name }}[i] = GP_Pixel_GET_{{ c.name }}_{{ pt.name }}(pix);
- %% endfor
+@ end
i++;
yi++;
@@ -241,39 +216,39 @@ static int v_lin_conv_{{ pt.name }}(const GP_Context *src,
/* Copy the rest the border pixel when we are out again */
while (i < size) {
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
{{ c.name }}[i] = GP_Pixel_GET_{{ c.name }}_{{ pt.name }}(pix);
- %% endfor
+@ end
i++;
}
for (y = 0; y < (GP_Coord)h_src; y++) {
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
int32_t {{ c.name }}_sum = MUL/2;
int *p{{ c.name }} = {{ c.name }} + y;
- %% endfor
+@ end
/* count the pixel value from neighbours weighted by kernel */
for (i = 0; i < kh; i++) {
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
{{ c.name }}_sum += (*p{{ c.name }}++) * ikernel[i];
- %% endfor
+@ end
}
/* divide the result */
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
{{ c.name }}_sum /= ikern_div;
- %% endfor
+@ end
/* and clamp just to be extra sure */
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
{{ c.name }}_sum = GP_CLAMP({{ c.name }}_sum, 0, {{ c.max }});
- %% endfor
+@ end
GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(dst, x_dst + x, y_dst + y,
GP_Pixel_CREATE_{{ pt.name }}(
- {{ expand_chanslist(pt, "", "_sum") }}
+ {{ arr_to_params(pt.chan_names, "", "_sum") }}
));
}
@@ -289,8 +264,7 @@ static int v_lin_conv_{{ pt.name }}(const GP_Context *src,
return 0;
}
-%% endif
-%% endfor
+@ end
int GP_FilterVLinearConvolution_Raw(const GP_Context *src,
GP_Coord x_src, GP_Coord y_src,
@@ -305,23 +279,22 @@ int GP_FilterVLinearConvolution_Raw(const GP_Context *src,
kh, x_src, y_src, w_src, h_src);
switch (src->pixel_type) {
- %% for pt in pixeltypes
- %% if not pt.is_unknown() and not pt.is_palette()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown() and not pt.is_palette():
case GP_PIXEL_{{ pt.name }}:
return v_lin_conv_{{ pt.name }}(src, x_src, y_src, w_src, h_src,
dst, x_dst, y_dst,
kernel, kh, kern_div, callback);
break;
- %% endif
- %% endfor
+@ end
default:
errno = EINVAL;
return -1;
}
}
-%% for pt in pixeltypes
-%% if not pt.is_unknown() and not pt.is_palette()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown() and not pt.is_palette():
static int lin_conv_{{ pt.name }}(const GP_Context *src,
GP_Coord x_src, GP_Coord y_src,
@@ -336,9 +309,9 @@ static int lin_conv_{{ pt.name }}(const GP_Context *src,
/* Do linear convolution */
for (y = 0; y < (GP_Coord)h_src; y++) {
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
uint32_t {{ c.name }}[kw][kh];
- %% endfor
+@ end
GP_Pixel pix;
/* Prefill the buffer on the start */
@@ -352,18 +325,18 @@ static int lin_conv_{{ pt.name }}(const GP_Context *src,
pix = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(src, xi, yi);
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
{{ c.name }}[i][j] = GP_Pixel_GET_{{ c.name }}_{{ pt.name }}(pix);
- %% endfor
+@ end
}
}
int idx = kw - 1;
for (x = 0; x < (GP_Coord)w_src; x++) {
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
float {{ c.name }}_sum = 0;
- %% endfor
+@ end
for (j = 0; j < kh; j++) {
int xi = x_src + x + kw/2;
@@ -374,9 +347,9 @@ static int lin_conv_{{ pt.name }}(const GP_Context *src,
pix = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(src, xi, yi);
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
{{ c.name }}[idx][j] = GP_Pixel_GET_{{ c.name }}_{{ pt.name }}(pix);
- %% endfor
+@ end
}
/* Count the pixel value from neighbours weighted by kernel */
@@ -389,23 +362,23 @@ static int lin_conv_{{ pt.name }}(const GP_Context *src,
k = i - idx - 1;
for (j = 0; j < kh; j++) {
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
{{ c.name }}_sum += {{ c.name }}[i][j] * kernel[k + j * kw];
- %% endfor
+@ end
}
}
/* divide the result */
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
{{ c.name }}_sum /= kern_div;
- %% endfor
+@ end
/* and clamp just to be extra sure */
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
int {{ c.name }}_res = GP_CLAMP((int){{ c.name }}_sum, 0, {{ c.max }});
- %% endfor
+@ end
- pix = GP_Pixel_CREATE_{{ pt.name }}({{ expand_chanslist(pt, "", "_res") }});
+ pix = GP_Pixel_CREATE_{{ pt.name }}({{ arr_to_params(pt.chan_names, "", "_res") }});
GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(dst, x_dst + x, y_dst + y, pix);
@@ -423,8 +396,7 @@ static int lin_conv_{{ pt.name }}(const GP_Context *src,
return 0;
}
-%% endif
-%% endfor
+@ end
int GP_FilterLinearConvolution_Raw(const GP_Context *src,
GP_Coord x_src, GP_Coord y_src,
@@ -438,19 +410,16 @@ int GP_FilterLinearConvolution_Raw(const GP_Context *src,
kw, kh, w_src, h_src);
switch (src->pixel_type) {
- %% for pt in pixeltypes
- %% if not pt.is_unknown() and not pt.is_palette()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown() and not pt.is_palette():
case GP_PIXEL_{{ pt.name }}:
return lin_conv_{{ pt.name }}(src, x_src, y_src, w_src, h_src,
dst, x_dst, y_dst,
kernel, kw, kh, kern_div, callback);
break;
- %% endif
- %% endfor
+@ end
default:
errno = EINVAL;
return -1;
}
}
-
-%% endblock body
diff --git a/libs/filters/GP_MirrorH.gen.c.t b/libs/filters/GP_MirrorH.gen.c.t
index e190c37b..e926bba3 100644
--- a/libs/filters/GP_MirrorH.gen.c.t
+++ b/libs/filters/GP_MirrorH.gen.c.t
@@ -1,36 +1,15 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.c.t"
-
-{% block descr %}Horizontal Mirror alogorithm{% endblock %}
-
-%% block body
+@ include source.t
+/*
+ * Horizontal Mirror alogorithm
+ *
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include "core/GP_GetPutPixel.h"
#include "core/GP_Debug.h"
#include "GP_Rotate.h"
-%% for ps in pixelsizes
+@ for ps in pixelsizes:
static int GP_MirrorH_Raw_{{ ps.suffix }}(const GP_Context *src,
GP_Context *dst,
GP_ProgressCallback *callback)
@@ -63,8 +42,8 @@ static int GP_MirrorH_Raw_{{ ps.suffix }}(const GP_Context *src,
return 0;
}
-%% endfor
-
+@ end
+@
static int GP_FilterMirrorH_Raw(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
@@ -105,6 +84,3 @@ GP_Context *GP_FilterMirrorHAlloc(const GP_Context *src,
return res;
}
-
-
-%% endblock body
diff --git a/libs/filters/GP_MultiTone.gen.c.t b/libs/filters/GP_MultiTone.gen.c.t
index 4329a3f1..2039a93c 100644
--- a/libs/filters/GP_MultiTone.gen.c.t
+++ b/libs/filters/GP_MultiTone.gen.c.t
@@ -1,32 +1,9 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "filter.c.t"
-
-%% block descr
-Generic Point filer
-%% endblock
-
-%% block body
+@ include source.t
+/*
+ * Generic Point filer
+ *
+ * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include <errno.h>
@@ -38,8 +15,8 @@ Generic Point filer
#include "filters/GP_MultiTone.h"
-%% for pt in pixeltypes
-%% if not pt.is_unknown() and not pt.is_palette()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown() and not pt.is_palette():
static void init_table_{{ pt.name }}(GP_Pixel table[],
GP_Size table_size,
GP_Pixel pixels[],
@@ -67,22 +44,21 @@ static void init_table_{{ pt.name }}(GP_Pixel table[],
// GP_PixelPrint(table[i], GP_PIXEL_{{ pt.name }});
}
}
-%% endif
-%% endfor
+@ end
+@
static void init_table(GP_PixelType type,
GP_Pixel table[], GP_Size table_size,
GP_Pixel pixels[], GP_Size pixels_size)
{
switch (type) {
-%% for pt in pixeltypes
-%% if not pt.is_unknown() and not pt.is_palette()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown() and not pt.is_palette():
case GP_PIXEL_{{ pt.name }}:
init_table_{{ pt.name }}(table, table_size,
pixels, pixels_size);
break;
-%% endif
-%% endfor
+@ end
default:
GP_BUG("Should not be reached");
break;
@@ -91,8 +67,8 @@ static void init_table(GP_PixelType type,
#include <assert.h>
-%% for pt in pixeltypes
-%% if pt.is_gray()
+@ for pt in pixeltypes:
+@ if pt.is_gray():
static int multitone_{{ pt.name }}(const GP_Context *const src,
GP_Coord x_src, GP_Coord y_src,
GP_Size w_src, GP_Size h_src,
@@ -101,7 +77,7 @@ static int multitone_{{ pt.name }}(const GP_Context *const src,
GP_Pixel pixels[], GP_Size pixels_size,
GP_ProgressCallback *callback)
{
-%% set size = pt.chanslist[0].max + 1
+@ size = pt.chanslist[0].max + 1
GP_TempAllocCreate(tmp, {{ size }} * sizeof(GP_Pixel));
GP_Pixel *table = GP_TempAllocGet(tmp, {{ size }} * sizeof(GP_Pixel));
@@ -139,9 +115,8 @@ static int multitone_{{ pt.name }}(const GP_Context *const src,
return 0;
}
-%% endif
-%% endfor
-
+@ end
+@
int GP_FilterMultiToneEx(const GP_Context *const src,
GP_Coord x_src, GP_Coord y_src,
GP_Size w_src, GP_Size h_src,
@@ -153,8 +128,8 @@ int GP_FilterMultiToneEx(const GP_Context *const src,
//CHECK DST IS NOT PALETTE PixelHasFlags
switch (src->pixel_type) {
-%% for pt in pixeltypes
-%% if pt.is_gray()
+@ for pt in pixeltypes:
+@ if pt.is_gray():
case GP_PIXEL_{{ pt.name }}:
return multitone_{{ pt.name }}(src, x_src, y_src,
w_src, h_src, dst,
@@ -162,8 +137,7 @@ int GP_FilterMultiToneEx(const GP_Context *const src,
pixels, pixels_size,
callback);
break;
-%% endif
-%% endfor
+@ end
default:
errno = EINVAL;
return -1;
@@ -197,5 +171,3 @@ GP_Context *GP_FilterMultiToneExAlloc(const GP_Context *const src,
return res;
}
-
-%% endblock body
diff --git a/libs/filters/GP_ResizeCubic.gen.c.t b/libs/filters/GP_ResizeCubic.gen.c.t
index ae849013..39abb557 100644
--- a/libs/filters/GP_ResizeCubic.gen.c.t
+++ b/libs/filters/GP_ResizeCubic.gen.c.t
@@ -1,30 +1,9 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "filter.c.t"
-
-{% block descr %}Cubic resampling{% endblock %}
-
-%% block body
+@ include source.t
+/*
+ * Cubic resampling
+ *
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include <errno.h>
#include <math.h>
@@ -51,15 +30,14 @@
#define SUM_I(a) ((a)[0] + (a)[1] + (a)[2] + (a)[3])
-%% for pt in pixeltypes
-%% if not pt.is_unknown() and not pt.is_palette()
-
+@ for pt in pixeltypes:
+@ if not pt.is_unknown() and not pt.is_palette():
static int resize_cubic_{{ pt.name }}(const GP_Context *src,
GP_Context *dst, GP_ProgressCallback *callback)
{
- %% for c in pt.chanslist
- int32_t col_{{ c[0] }}[src->w];
- %% endfor
+@ for c in pt.chanslist:
+ int32_t col_{{ c.name }}[src->w];
+@ end
uint32_t i, j;
@@ -67,7 +45,7 @@ static int resize_cubic_{{ pt.name }}(const GP_Context *src,
src->w, src->h, dst->w, dst->h,
1.00 * dst->w / src->w, 1.00 * dst->h / src->h);
-{{ fetch_gamma_tables(pt, "src") }}
+ {@ fetch_gamma_tables(pt, "src") @}
/* pre-generate x mapping and constants */
int32_t xmap[dst->w][4];
@@ -113,9 +91,9 @@ static int resize_cubic_{{ pt.name }}(const GP_Context *src,
/* Generate interpolated row */
for (j = 0; j < src->w; j++) {
- %% for c in pt.chanslist
- int32_t {{ c[0] }}v[4];
- %% endfor
+@ for c in pt.chanslist:
+ int32_t {{ c.name }}v[4];
+@ end
GP_Pixel pix[4];
pix[0] = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(src, j, yi[0]);
@@ -123,67 +101,67 @@ static int resize_cubic_{{ pt.name }}(const GP_Context *src,
pix[2] = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(src, j, yi[2]);
pix[3] = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(src, j, yi[3]);
- %% for c in pt.chanslist
- {{ c[0] }}v[0] = GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix[0]);
- {{ c[0] }}v[1] = GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix[1]);
- {{ c[0] }}v[2] = GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix[2]);
- {{ c[0] }}v[3] = GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix[3]);
- %% endfor
+@ for c in pt.chanslist:
+ {{ c.name }}v[0] = GP_Pixel_GET_{{ c.name }}_{{ pt.name }}(pix[0]);
+ {{ c.name }}v[1] = GP_Pixel_GET_{{ c.name }}_{{ pt.name }}(pix[1]);
+ {{ c.name }}v[2] = GP_Pixel_GET_{{ c.name }}_{{ pt.name }}(pix[2]);
+ {{ c.name }}v[3] = GP_Pixel_GET_{{ c.name }}_{{ pt.name }}(pix[3]);
+@ end
if (src->gamma) {
- %% for c in pt.chanslist
- {{ c[0] }}v[0] = {{ c[0] }}_2_LIN[{{ c[0] }}v[0]];
- {{ c[0] }}v[1] = {{ c[0] }}_2_LIN[{{ c[0] }}v[1]];
- {{ c[0] }}v[2] = {{ c[0] }}_2_LIN[{{ c[0] }}v[2]];
- {{ c[0] }}v[3] = {{ c[0] }}_2_LIN[{{ c[0] }}v[3]];
- %% endfor
+@ for c in pt.chanslist:
+ {{ c.name }}v[0] = {{ c.name }}_2_LIN[{{ c.name }}v[0]];
+ {{ c.name }}v[1] = {{ c.name }}_2_LIN[{{ c.name }}v[1]];
+ {{ c.name }}v[2] = {{ c.name }}_2_LIN[{{ c.name }}v[2]];
+ {{ c.name }}v[3] = {{ c.name }}_2_LIN[{{ c.name }}v[3]];
+@ end
}
- %% for c in pt.chanslist
- MUL_I({{ c[0] }}v, cvy);
- %% endfor
+@ for c in pt.chanslist:
+ MUL_I({{ c.name }}v, cvy);
+@ end
- %% for c in pt.chanslist
- col_{{ c[0] }}[j] = SUM_I({{ c[0] }}v);
- %% endfor
+@ for c in pt.chanslist:
+ col_{{ c.name }}[j] = SUM_I({{ c.name }}v);
+@ end
}
/* now interpolate column for new image */
for (j = 0; j < dst->w; j++) {
- %% for c in pt.chanslist
- int32_t {{ c[0] }}v[4];
- int32_t {{ c[0] }};
- %% endfor
-
- %% for c in pt.chanslist
- {{ c[0] }}v[0] = col_{{ c[0] }}[xmap[j][0]];
- {{ c[0] }}v[1] = col_{{ c[0] }}[xmap[j][1]];
- {{ c[0] }}v[2] = col_{{ c[0] }}[xmap[j][2]];
- {{ c[0] }}v[3] = col_{{ c[0] }}[xmap[j][3]];
- %% endfor
-
- %% for c in pt.chanslist
- MUL_I({{ c[0] }}v, xmap_c[j]);
- %% endfor
-
- %% for c in pt.chanslist
- {{ c[0] }} = (SUM_I({{ c[0] }}v) + MUL*MUL/2) / MUL / MUL;
- %% endfor
+@ for c in pt.chanslist:
+ int32_t {{ c.name }}v[4];
+ int32_t {{ c.name }};
+@ end
+
+@ for c in pt.chanslist:
+ {{ c.name }}v[0] = col_{{ c.name }}[xmap[j][0]];
+ {{ c.name }}v[1] = col_{{ c.name }}[xmap[j][1]];
+ {{ c.name }}v[2] = col_{{ c.name }}[xmap[j][2]];
+ {{ c.name }}v[3] = col_{{ c.name }}[xmap[j][3]];
+@ end
+
+@ for c in pt.chanslist:
+ MUL_I({{ c.name }}v, xmap_c[j]);
+@ end
+
+@ for c in pt.chanslist:
+ {{ c.name }} = (SUM_I({{ c.name }}v) + MUL*MUL/2) / MUL / MUL;
+@ end
if (src->gamma) {
- %% for c in pt.chanslist
- {{ c[0] }} = GP_CLAMP_GENERIC({{ c[0] }}, 0, {{ 2 ** (c[2] + 2) - 1 }});
- %% endfor
- %% for c in pt.chanslist
- {{ c[0] }} = {{ c[0] }}_2_GAMMA[{{ c[0] }}];
- %% endfor
+@ for c in pt.chanslist:
+ {{ c.name }} = GP_CLAMP_GENERIC({{ c.name }}, 0, {{ 2 ** (c[2] + 2) - 1 }});
+@ end
+@ for c in pt.chanslist:
+ {{ c.name }} = {{ c.name }}_2_GAMMA[{{ c.name }}];
+@ end
} else {
- %% for c in pt.chanslist
- {{ c[0] }} = GP_CLAMP_GENERIC({{ c[0] }}, 0, {{ 2 ** c[2] - 1 }});
- %% endfor
+@ for c in pt.chanslist:
+ {{ c.name }} = GP_CLAMP_GENERIC({{ c.name }}, 0, {{ 2 ** c[2] - 1 }});
+@ end
}
- GP_Pixel pix = GP_Pixel_CREATE_{{ pt.name }}({{ expand_chanslist(pt, "(uint8_t)") }});
+ GP_Pixel pix = GP_Pixel_CREATE_{{ pt.name }}({{ arr_to_params(pt.chan_names, "(uint8_t)") }});
GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(dst, j, i, pix);
}
@@ -195,20 +173,18 @@ static int resize_cubic_{{ pt.name }}(const GP_Context *src,
return 0;
}
-%% endif
-%% endfor
-
+@ end
+@
static int resize_cubic(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
switch (src->pixel_type) {
- %% for pt in pixeltypes
- %% if not pt.is_unknown() and not pt.is_palette()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown() and not pt.is_palette():
case GP_PIXEL_{{ pt.name }}:
return resize_cubic_{{ pt.name }}(src, dst, callback);
break;
- %% endif
- %% endfor
+@ end
default:
errno = EINVAL;
return -1;
@@ -226,5 +202,3 @@ int GP_FilterResizeCubicInt(const GP_Context *src, GP_Context *dst,
return resize_cubic(src, dst, callback);
}
-
-%% endblock body
diff --git a/libs/filters/GP_ResizeLinear.gen.c.t b/libs/filters/GP_ResizeLinear.gen.c.t
index 6a2b947d..cfa38928 100644
--- a/libs/filters/GP_ResizeLinear.gen.c.t
+++ b/libs/filters/GP_ResizeLinear.gen.c.t
@@ -1,30 +1,9 @@
-/*****************************************************************************
- * 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> *
- * *
- *****************************************************************************/
-
-%% extends "filter.c.t"
-
-{% block descr %}Linear resampling{% endblock %}
-
-%% block body
+@ include source.t
+/*
+ * Linear resampling
+ *
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include <string.h>
#include <errno.h>
@@ -36,41 +15,40 @@
#include "core/GP_Debug.h"
#include "GP_Resize.h"
-
-%%- macro fetch_rows(pt, y)
- for (x = 0; x < src->w; x++) {
- GP_Pixel pix = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(src, x, {{ y }});
-%% for c in pt.chanslist
- {{ c.name }}[x] = GP_Pixel_GET_{{ c.name }}_{{ pt.name }}(pix);
-%% endfor
- }
-%% endmacro
-
-%%- macro sum_rows(pt, mult)
- for (x = 0; x < dst->w; x++) {
- /* Get first left pixel */
-%% for c in pt.chanslist
- uint32_t {{ c.name }}_middle = 0;
- uint32_t {{ c.name }}_first = {{ c.name }}[xmap[x]] * (MULT - xoff[x]);
-%% endfor
- /* Sum middle pixels */
- for (j = xmap[x]+1; j < xmap[x+1]; j++) {
-%% for c in pt.chanslist
- {{ c.name }}_middle += {{ c.name }}[j];
-%% endfor
- }
- /* Add it all together with last pixel on the right */
-%% for c in pt.chanslist
- {{ c.name }}_res[x] += ({{ c.name }}_middle * (MULT / DIV) +
- ({{ c.name }}[xmap[x+1]] * xoff[x+1] +
- {{ c.name }}_first) / DIV) * {{ mult }} / DIV;
-%% endfor
+@
+@ def fetch_rows(pt, y):
+for (x = 0; x < src->w; x++) {
+ GP_Pixel pix = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(src, x, {{ y }});
+@ for c in pt.chanslist:
+ {{ c.name }}[x] = GP_Pixel_GET_{{ c.name }}_{{ pt.name }}(pix);
+@ end
+}
+@ end
+@
+@ def sum_rows(pt, mult):
+for (x = 0; x < dst->w; x++) {
+ /* Get first left pixel */
+@ for c in pt.chanslist:
+ uint32_t {{ c.name }}_middle = 0;
+ uint32_t {{ c.name }}_first = {{ c.name }}[xmap[x]] * (MULT - xoff[x]);
+@ end
+ /* Sum middle pixels */
+ for (j = xmap[x]+1; j < xmap[x+1]; j++) {
+@ for c in pt.chanslist:
+ {{ c.name }}_middle += {{ c.name }}[j];
+@ end
+ }
+ /* Add it all together with last pixel on the right */
+@ for c in pt.chanslist:
+ {{ c.name }}_res[x] += ({{ c.name }}_middle * (MULT / DIV) +
+ ({{ c.name }}[xmap[x+1]] * xoff[x+1] +
+ {{ c.name }}_first) / DIV) * {{ mult }} / DIV;
+@ end
}
-%% endmacro
-
-%% for pt in pixeltypes
-%% if not pt.is_unknown() and not pt.is_palette()
+@ end
+@ for pt in pixeltypes:
+@ if not pt.is_unknown() and not pt.is_palette():
static int resize_lin_lf_{{ pt.name }}(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
@@ -78,19 +56,19 @@ static int resize_lin_lf_{{ pt.name }}(const GP_Context *src, GP_Context *dst,
uint32_t ymap[dst->h + 1];
uint32_t xoff[dst->w + 1];
uint32_t yoff[dst->h + 1];
-%% for c in pt.chanslist
+@ for c in pt.chanslist:
uint32_t {{ c.name }}[src->w];
-%% endfor
+@ end
uint32_t x, y;
uint32_t i, j;
-{# Reduce fixed point bits for > 8 bits per channel (fixed 16 bit Grayscale) #}
-%% if pt.chanslist[0].size > 8
+@ # Reduce fixed point bits for > 8 bits per channel (fixed 16 bit Grayscale)
+@ if pt.chanslist[0].size > 8:
const int MULT=1<<10;
const int DIV=1<<6;
-%% else
+@ else:
const int MULT=1<<14;
const int DIV=1<<9;
-%% endif
+@ end
/* Pre-compute mapping for interpolation */
for (i = 0; i <= dst->w; i++) {
@@ -107,38 +85,38 @@ static int resize_lin_lf_{{ pt.name }}(const GP_Context *src, GP_Context *dst,
uint32_t div = (((uint64_t)(xmap[1] * MULT + xoff[1]) * ((uint64_t)ymap[1] * MULT + yoff[1]) + DIV/2) / DIV + DIV/2)/DIV;
/* Prefetch first row */
- {{ fetch_rows(pt, 0) }}
+ {@ fetch_rows(pt, 0) @}
for (y = 0; y < dst->h; y++) {
-%% for c in pt.chanslist
+@ for c in pt.chanslist:
uint32_t {{ c.name }}_res[dst->w];
-%% endfor
+@ end
-%% for c in pt.chanslist
+@ for c in pt.chanslist:
memset({{ c.name }}_res, 0, sizeof({{ c.name }}_res));
-%% endfor
+@ end
/* Sum first row */
- {{ sum_rows(pt, '(MULT-yoff[y])') }}
+ {@ sum_rows(pt, '(MULT-yoff[y])') @}
/* Sum middle */
for (i = ymap[y]+1; i < ymap[y+1]; i++) {
- {{ fetch_rows(pt, 'i') }}
- {{ sum_rows(pt, 'MULT') }}
+ {@ fetch_rows(pt, 'i') @}
+ {@ sum_rows(pt, 'MULT') @}
}
/* Sum last row */
if (yoff[y+1]) {
- {{ fetch_rows(pt, 'ymap[y+1]') }}
- {{ sum_rows(pt, 'yoff[y+1]') }}
+ {@ fetch_rows(pt, 'ymap[y+1]') @}
+ {@ sum_rows(pt, 'yoff[y+1]') @}
}
for (x = 0; x < dst->w; x++) {
-%% for c in pt.chanslist
+@ for c in pt.chanslist:
uint32_t {{ c.name }}_p = ({{ c.name }}_res[x] + div/2) / div;
-%% endfor
+@ end
GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(dst, x, y,
- GP_Pixel_CREATE_{{ pt.name }}({{ expand_chanslist(pt, '', '_p') }}));
+ GP_Pixel_CREATE_{{ pt.name }}({{ arr_to_params(pt.chan_names, '', '_p') }}));
}
if (GP_ProgressCallbackReport(callback, y, dst->h, dst->w))
@@ -149,12 +127,10 @@ static int resize_lin_lf_{{ pt.name }}(const GP_Context *src, GP_Context *dst,
return 0;
}
-%% endif
-%% endfor
-
-%% for pt in pixeltypes
-%% if not pt.is_unknown() and not pt.is_palette()
-
+@ end
+@
+@ for pt in pixeltypes:
+@ if not pt.is_unknown() and not pt.is_palette():
static int resize_lin{{ pt.name }}(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
@@ -190,9 +166,9 @@ static int resize_lin{{ pt.name }}(const GP_Context *src, GP_Context *dst,
for (x = 0; x < dst->w; x++) {
GP_Pixel pix00, pix01, pix10, pix11;
GP_Coord x0, x1, y0, y1;
- %% for c in pt.chanslist
+@ for c in pt.chanslist:
uint32_t {{ c[0] }}, {{ c[0] }}0, {{ c[0] }}1;
- %% endfor
+@ end
x0 = xmap[x];
x1 = xmap[x] + 1;
@@ -211,28 +187,28 @@ static int resize_lin{{ pt.name }}(const GP_Context *src, GP_Context *dst,
pix01 = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(src, x0, y1);
pix11 = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(src, x1, y1);
- %% for c in pt.chanslist
- {{ c[0] }}0 = GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix00) * (255 - xoff[x]);
- %% endfor
+@ for c in pt.chanslist:
+ {{ c.name }}0 = GP_Pixel_GET_{{ c.name }}_{{ pt.name }}(pix00) * (255 - xoff[x]);
+@ end
- %% for c in pt.chanslist
- {{ c[0] }}0 += GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix10) * xoff[x];
- %% endfor
+@ for c in pt.chanslist:
+ {{ c.name }}0 += GP_Pixel_GET_{{ c.name }}_{{ pt.name }}(pix10) * xoff[x];
+@ end
- %% for c in pt.chanslist
- {{ c[0] }}1 = GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix01) * (255 - xoff[x]);
- %% endfor
+@ for c in pt.chanslist:
+ {{ c.name }}1 = GP_Pixel_GET_{{ c.name }}_{{ pt.name }}(pix01) * (255 - xoff[x]);
+@ end
- %% for c in pt.chanslist
- {{ c[0] }}1 += GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix11) * xoff[x];
- %% endfor
+@ for c in pt.chanslist:
+ {{ c.name }}1 += GP_Pixel_GET_{{ c.name }}_{{ pt.name }}(pix11) * xoff[x];
+@ end
- %% for c in pt.chanslist
- {{ c[0] }} = ({{ c[0] }}1 * yoff[y] + {{ c[0] }}0 * (255 - yoff[y]) + (1<<15)) >> 16;
- %% endfor
+@ for c in pt.chanslist:
+ {{ c.name }} = ({{ c.name }}1 * yoff[y] + {{ c.name }}0 * (255 - yoff[y]) + (1<<15)) >> 16;
+@ end
GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(dst, x, y,
- GP_Pixel_CREATE_{{ pt.name }}({{ expand_chanslist(pt, "") }}));
+ GP_Pixel_CREATE_{{ pt.name }}({{ arr_to_params(pt.chan_names) }}));
}
if (GP_ProgressCallbackReport(callback, y, dst->h, dst->w))
@@ -243,20 +219,18 @@ static int resize_lin{{ pt.name }}(const GP_Context *src, GP_Context *dst,
return 0;
}
-%% endif
-%% endfor
-
+@ end
+@
static int resize_lin(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
switch (src->pixel_type) {
-%% for pt in pixeltypes
-%% if not pt.is_unknown() and not pt.is_palette()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown() and not pt.is_palette():
case GP_PIXEL_{{ pt.name }}:
return resize_lin{{ pt.name }}(src, dst, callback);
break;
-%% endif
-%% endfor
+@ end
default:
GP_WARN("Invalid pixel type %s",
GP_PixelTypeName(src->pixel_type));
@@ -289,13 +263,12 @@ static int resize_lin_lf(const GP_Context *src, GP_Context *dst,
src->w, src->h, dst->w, dst->h, x_rat, y_rat);
switch (src->pixel_type) {
-%% for pt in pixeltypes
-%% if not pt.is_unknown() and not pt.is_palette()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown() and not pt.is_palette():
case GP_PIXEL_{{ pt.name }}:
return resize_lin_lf_{{ pt.name }}(src, dst, callback);
break;
-%% endif
-%% endfor
+@ end
default:
GP_WARN("Invalid pixel type %s",
GP_PixelTypeName(src->pixel_type));
@@ -321,5 +294,3 @@ int GP_FilterResizeLinearLFInt(const GP_Context *src, GP_Context *dst,
return resize_lin_lf(src, dst, callback);
}
-
-%% endblock body
diff --git a/libs/filters/GP_ResizeNN.gen.c.t b/libs/filters/GP_ResizeNN.gen.c.t
index 48742883..82ef9cdf 100644
--- a/libs/filters/GP_ResizeNN.gen.c.t
+++ b/libs/filters/GP_ResizeNN.gen.c.t
@@ -1,30 +1,9 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "filter.c.t"
-
-{% block descr %}Nearest Neighbour resampling{% endblock %}
-
-%% block body
+@ include source.t
+/*
+ * Nearest Neighbour resampling
+ *
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include <errno.h>
@@ -35,9 +14,8 @@
#include "GP_ResizeNN.h"
-%% for pt in pixeltypes
-%% if not pt.is_unknown()
-
+@ for pt in pixeltypes:
+@ if not pt.is_unknown():
static int resize_nn{{ pt.name }}(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
@@ -75,20 +53,18 @@ static int resize_nn{{ pt.name }}(const GP_Context *src, GP_Context *dst,
return 0;
}
-%% endif
-%% endfor
-
+@ end
+@
static int resize_nn(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
switch (src->pixel_type) {
- %% for pt in pixeltypes
- %% if not pt.is_unknown()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown():
case GP_PIXEL_{{ pt.name }}:
return resize_nn{{ pt.name }}(src, dst, callback);
break;
- %% endif
- %% endfor
+@ end
default:
return -1;
}
@@ -105,5 +81,3 @@ int GP_FilterResizeNN(const GP_Context *src, GP_Context *dst,
return resize_nn(src, dst, callback);
}
-
-%% endblock body
diff --git a/libs/filters/GP_Rotate.gen.c.t b/libs/filters/GP_Rotate.gen.c.t
index 05c404c1..6c5660b2 100644
--- a/libs/filters/GP_Rotate.gen.c.t
+++ b/libs/filters/GP_Rotate.gen.c.t
@@ -1,36 +1,15 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.c.t"
-
-{% block descr %}Vertical Mirror alogorithm{% endblock %}
-
-%% block body
+@ include source.t
+/*
+ * Vertical Mirror alogorithm
+ *
+ * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include "core/GP_Debug.h"
#include "core/GP_GetPutPixel.h"
#include "GP_Rotate.h"
-%% for ps in pixelsizes
+@ for ps in pixelsizes:
static int GP_FilterRotate90_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
@@ -52,8 +31,8 @@ static int GP_FilterRotate90_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Conte
return 0;
}
-%% endfor
-
+@ end
+@
static int GP_FilterRotate90_Raw(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
@@ -96,14 +75,14 @@ GP_Context *GP_FilterRotate90Alloc(const GP_Context *src,
return res;
}
-%% macro swap_pixels(ps, src, dst, x0, y0, x1, y1)
- GP_Pixel pix0 = GP_GetPixel_Raw_{{ ps.suffix }}({{ src }}, {{ x0 }}, {{ y0 }});
- GP_Pixel pix1 = GP_GetPixel_Raw_{{ ps.suffix }}({{ src }}, {{ x1 }}, {{ y1 }});
- GP_PutPixel_Raw_{{ ps.suffix }}({{ dst }}, {{ x0 }}, {{ y0 }}, pix1);
- GP_PutPixel_Raw_{{ ps.suffix }}({{ dst }}, {{ x1 }}, {{ y1 }}, pix0);
-%% endmacro
-
-%% for ps in pixelsizes
+@ def swap_pixels(ps, src, dst, x0, y0, x1, y1):
+GP_Pixel pix0 = GP_GetPixel_Raw_{{ ps.suffix }}({{ src }}, {{ x0 }}, {{ y0 }});
+GP_Pixel pix1 = GP_GetPixel_Raw_{{ ps.suffix }}({{ src }}, {{ x1 }}, {{ y1 }});
+GP_PutPixel_Raw_{{ ps.suffix }}({{ dst }}, {{ x0 }}, {{ y0 }}, pix1);
+GP_PutPixel_Raw_{{ ps.suffix }}({{ dst }}, {{ x1 }}, {{ y1 }}, pix0);
+@ end
+@
+@ for ps in pixelsizes:
static int GP_FilterRotate180_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
@@ -116,7 +95,7 @@ static int GP_FilterRotate180_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Cont
uint32_t xr = src->w - x - 1;
uint32_t yr = src->h - y - 1;
- {{ swap_pixels(ps, 'src', 'dst', 'x', 'y', 'xr', 'yr') }}
+ {@ swap_pixels(ps, 'src', 'dst', 'x', 'y', 'xr', 'yr') @}
}
if (GP_ProgressCallbackReport(callback, x, src->w, src->h))
@@ -127,8 +106,8 @@ static int GP_FilterRotate180_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Cont
return 0;
}
-%% endfor
-
+@ end
+@
static int GP_FilterRotate180_Raw(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
@@ -171,7 +150,7 @@ GP_Context *GP_FilterRotate180Alloc(const GP_Context *src,
return res;
}
-%% for ps in pixelsizes
+@ for ps in pixelsizes:
static int GP_FilterRotate270_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
@@ -193,8 +172,8 @@ static int GP_FilterRotate270_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Cont
return 0;
}
-%% endfor
-
+@ end
+@
static int GP_FilterRotate270_Raw(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
@@ -236,5 +215,3 @@ GP_Context *GP_FilterRotate270Alloc(const GP_Context *src,
return res;
}
-
-%% endblock body
diff --git a/libs/filters/Makefile b/libs/filters/Makefile
index 9c5f30f6..5eca5abb 100644
--- a/libs/filters/Makefile
+++ b/libs/filters/Makefile
@@ -1,14 +1,15 @@
TOPDIR=../..
include $(TOPDIR)/pre.mk
-STATS_FILTERS=GP_Histogram.gen.c
+#STATS_FILTERS=GP_Histogram.gen.c
-POINT_FILTERS=GP_GaussianNoise.gen.c GP_ApplyTables.gen.c GP_Invert.gen.c+#POINT_FILTERS=GP_Invert.gen.c GP_Brightness.gen.c GP_Contrast.gen.c GP_BrightnessContrast.gen.c GP_Posterize.gen.c- GP_MultiTone.gen.c
-ARITHMETIC_FILTERS=GP_Difference.gen.c GP_Addition.gen.c GP_Min.gen.c+POINT_FILTERS=GP_GaussianNoise.gen.c GP_ApplyTables.gen.c GP_MultiTone.gen.c
+
+#ARITHMETIC_FILTERS=GP_Difference.gen.c GP_Addition.gen.c GP_Min.gen.c GP_Max.gen.c GP_Multiply.gen.c
RESAMPLING_FILTERS=GP_ResizeNN.gen.c GP_Cubic.gen.c GP_ResizeCubic.gen.c@@ -22,11 +23,6 @@ CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c))
LIBNAME=filters
INCLUDE=core
-include $(TOPDIR)/gen.mk
+include $(TOPDIR)/genn.mk
include $(TOPDIR)/lib.mk
include $(TOPDIR)/post.mk
-
-$(POINT_FILTERS) $(ARITHMETIC_FILTERS) $(STATS_FILTERS): $(TEMPLATE_DIR)/filter.c.t
-$(STATS_FILTERS): $(TEMPLATE_DIR)/filter.stats.c.t
-$(POINT_FILTERS): $(TEMPLATE_DIR)/filter.point.c.t
-$(ARITHMETIC_FILTERS): $(TEMPLATE_DIR)/filter.arithmetic.c.t
diff --git a/libs/gfx/GP_FillCircle.gen.c.t b/libs/gfx/GP_FillCircle.gen.c.t
index ac4c6ceb..856b13bb 100644
--- a/libs/gfx/GP_FillCircle.gen.c.t
+++ b/libs/gfx/GP_FillCircle.gen.c.t
@@ -1,33 +1,11 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2012 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.c.t"
-
-{% block descr %}A filled circle drawing algorithm.{% endblock %}
-
-%% block body
+@ include source.t
+/*
+ * A filled circle drawing algorithm.
+ *
+ * Copyright (C) 2009-2012 Jiri "BlueBear" Dluhos
+ * <jiri.bluebear.dluhos(a)gmail.com>
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include "core/GP_GetPutPixel.h"
#include "core/GP_Transform.h"
@@ -44,8 +22,7 @@
* until we accumulate enough Y changes to reach the next line,
* and then draw the full line. The top and bottom half are mirrored.
*/
-
-%% for ps in pixelsizes
+@ for ps in pixelsizes:
static void GP_FillCircle_Raw_{{ ps.suffix }}(GP_Context *context,
GP_Coord xcenter, GP_Coord ycenter, GP_Size r, GP_Pixel pixel)
@@ -68,7 +45,7 @@ static void GP_FillCircle_Raw_{{ ps.suffix }}(GP_Context *context,
}
}
-%% endfor
+@ end
void GP_FillCircle_Raw(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
GP_Size r, GP_Pixel pixel)
@@ -88,5 +65,3 @@ void GP_FillCircle(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
GP_FillCircle_Raw(context, xcenter, ycenter, r, pixel);
}
-
-%% endblock body
diff --git a/libs/gfx/GP_FillEllipse.gen.c.t b/libs/gfx/GP_FillEllipse.gen.c.t
index 325106e0..9638d478 100644
--- a/libs/gfx/GP_FillEllipse.gen.c.t
+++ b/libs/gfx/GP_FillEllipse.gen.c.t
@@ -1,33 +1,9 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.c.t"
-
-{% block descr %}A filled ellipse drawing algorithm.{% endblock %}
-
-%% block body
+@ include source.t
+/*
+ * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos
+ * <jiri.bluebear.dluhos(a)gmail.com>
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include "core/GP_GetPutPixel.h"
#include "core/GP_FnPerBpp.h"
@@ -44,7 +20,7 @@
* we just iterate X until Y reaches next line, and then draw the full line.
*/
-%% for ps in pixelsizes
+@ for ps in pixelsizes:
static void GP_FillEllipse_Raw_{{ ps.suffix }}(GP_Context *context, GP_Coord xcenter,
GP_Coord ycenter, GP_Size a, GP_Size b, GP_Pixel pixel)
@@ -73,7 +49,7 @@ static void GP_FillEllipse_Raw_{{ ps.suffix }}(GP_Context *context, GP_Coord xce
}
}
-%% endfor
+@ end
void GP_FillEllipse_Raw(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
GP_Size a, GP_Size b, GP_Pixel pixel)
@@ -94,5 +70,3 @@ void GP_FillEllipse(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
GP_FillEllipse_Raw(context, xcenter, ycenter, a, b, pixel);
}
-
-%% endblock body
diff --git a/libs/gfx/GP_HLine.gen.c.t b/libs/gfx/GP_HLine.gen.c.t
index 4a9ea1e9..f5caae70 100644
--- a/libs/gfx/GP_HLine.gen.c.t
+++ b/libs/gfx/GP_HLine.gen.c.t
@@ -1,48 +1,25 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2011 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
- * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.c.t"
-
-{% block descr %}Horizontal line drawing{% endblock %}
-
-%% block body
+@ include source.t
+/*
+ * Horizontal line drawing
+ *
+ * Copyright (C) 2009-2011 Jiri "BlueBear" Dluhos
+ * <jiri.bluebear.dluhos(a)gmail.com>
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include "core/GP_GetPutPixel.gen.h"
#include "core/GP_WritePixel.h"
#include "gfx/GP_HLine.h"
-{# Explicit list of BPP that have optimized write pixel #}
-%% set have_writepixels = ['1BPP_LE', '1BPP_BE',
- '2BPP_LE', '2BPP_BE',
- '4BPP_LE', '4BPP_BE',
- '8BPP', '16BPP',
- '24BPP', '32BPP']
-
-%% for ps in pixelsizes
-
+@ # Explicit list of BPP that have optimized write pixel
+@ have_writepixels = ['1BPP_LE', '1BPP_BE',
+@ '2BPP_LE', '2BPP_BE',
+@ '4BPP_LE', '4BPP_BE',
+@ '8BPP', '16BPP',
+@ '24BPP', '32BPP']
+@
+@ for ps in pixelsizes:
void GP_HLine_Raw_{{ ps.suffix }}(GP_Context *context, int x0, int x1, int y,
GP_Pixel pixel)
{
@@ -58,23 +35,19 @@ void GP_HLine_Raw_{{ ps.suffix }}(GP_Context *context, int x0, int x1, int y,
x0 = GP_MAX(x0, 0);
x1 = GP_MIN(x1, (int) context->w - 1);
-%% if ps.suffix in have_writepixels
+@ if ps.suffix in have_writepixels:
size_t length = 1 + x1 - x0;
void *start = GP_PIXEL_ADDR(context, x0, y);
-%% if ps.needs_bit_endian()
+@ if ps.needs_bit_endian():
unsigned int offset = GP_PIXEL_ADDR_OFFSET_{{ ps.suffix }}(x0);
GP_WritePixels_{{ ps.suffix }}(start, offset, length, pixel);
-%% else
+@ else:
GP_WritePixels_{{ ps.suffix }}(start, length, pixel);
-%% endif
-
-%% else
+@ else:
for (;x0 <= x1; x0++)
GP_PutPixel_Raw_{{ ps.suffix }}(context, x0, y, pixel);
-%% endif
+@ end
}
-%% endfor
-%% endblock body
diff --git a/libs/gfx/GP_HLineAA.gen.c.t b/libs/gfx/GP_HLineAA.gen.c.t
index 63fc0d62..2a4910fb 100644
--- a/libs/gfx/GP_HLineAA.gen.c.t
+++ b/libs/gfx/GP_HLineAA.gen.c.t
@@ -20,11 +20,7 @@
* *
*****************************************************************************/
-%% extends "base.c.t"
-
-{% block descr %}Anti Aliased Horizontal Line{% endblock %}
-
-%% block body
+/* Anti Aliased Horizontal Line */
#include "core/GP_Context.h"
#include "core/GP_MixPixels.h"
@@ -92,5 +88,3 @@ void GP_HLineAA_Raw(GP_Context *context, GP_Coord x0, GP_Coord x1,
GP_MixPixel_Raw_Clipped(context, x, int_y+1, pixel, lp);
}
}
-
-%% endblock body
diff --git a/libs/gfx/GP_Line.gen.c.t b/libs/gfx/GP_Line.gen.c.t
index d91b45a0..093a6742 100644
--- a/libs/gfx/GP_Line.gen.c.t
+++ b/libs/gfx/GP_Line.gen.c.t
@@ -1,33 +1,11 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2012 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.c.t"
-
-{% block descr %}Line drawing algorithm{% endblock %}
-
-%% block body
+@ include source.t
+/*
+ * Line drawing algorithm.
+ *
+ * Copyright (C) 2009-2012 Jiri "BlueBear" Dluhos
+ * <jiri.bluebear.dluhos(a)gmail.com>
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include "core/GP_Common.h"
#include "core/GP_GetPutPixel.h"
@@ -44,8 +22,7 @@
* for a nice and understandable description.
*/
-%% for ps in pixelsizes
-
+@ for ps in pixelsizes:
void GP_Line_Raw_{{ ps.suffix }}(GP_Context *context, int x0, int y0,
int x1, int y1, GP_Pixel pixval)
{
@@ -116,7 +93,7 @@ void GP_Line_Raw_{{ ps.suffix }}(GP_Context *context, int x0, int y0,
}
}
-%% endfor
+@ end
void GP_Line_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
GP_Coord x1, GP_Coord y1, GP_Pixel pixel)
@@ -137,5 +114,3 @@ void GP_Line(GP_Context *context, GP_Coord x0, GP_Coord y0,
GP_Line_Raw(context, x0, y0, x1, y1, pixel);
}
-
-%% endblock body
diff --git a/libs/gfx/GP_LineAA.gen.c.t b/libs/gfx/GP_LineAA.gen.c.t
index 845819e0..3029dfb5 100644
--- a/libs/gfx/GP_LineAA.gen.c.t
+++ b/libs/gfx/GP_LineAA.gen.c.t
@@ -20,11 +20,7 @@
* *
*****************************************************************************/
-%% extends "base.c.t"
-
-{% block descr %}Anti Aliased Line{% endblock %}
-
-%% block body
+/* Anti Aliased Line */
#include "core/GP_Context.h"
#include "core/GP_MixPixels.h"
@@ -157,5 +153,3 @@ void GP_LineAA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
else
line_aa_x(context, x0, y0, x1, y1, pixel);
}
-
-%% endblock body
diff --git a/libs/gfx/GP_PutPixelAA.gen.c.t b/libs/gfx/GP_PutPixelAA.gen.c.t
index b061bf9d..92cfbdb1 100644
--- a/libs/gfx/GP_PutPixelAA.gen.c.t
+++ b/libs/gfx/GP_PutPixelAA.gen.c.t
@@ -20,11 +20,7 @@
* *
*****************************************************************************/
-%% extends "base.c.t"
-
-{% block descr %}Anti Aliased Put Pixel{% endblock %}
-
-%% block body
+/* Anti Aliased Put Pixel */
#include "core/GP_Context.h"
#include "core/GP_MixPixels.h"
@@ -70,6 +66,3 @@ void GP_PutPixelAA(GP_Context *context, GP_Coord x, GP_Coord y, GP_Pixel pixel)
GP_PutPixelAA_Raw_Clipped(context, x, y, pixel);
}
-
-
-%% endblock body
diff --git a/libs/gfx/GP_VLine.gen.c.t b/libs/gfx/GP_VLine.gen.c.t
index d894f146..6870dea3 100644
--- a/libs/gfx/GP_VLine.gen.c.t
+++ b/libs/gfx/GP_VLine.gen.c.t
@@ -1,35 +1,14 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends 'base.h.t'
-
-{% block descr %}Vertical Line{% endblock %}
-
-{% block body %}
+@ include source.t
+/*
+ * Vertical Line drawing algorithm.
+ *
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include "core/GP_GetPutPixel.h"
#include "gfx/GP_VLine.gen.h"
-%% for ps in pixelsizes
+@ for ps in pixelsizes:
void GP_VLine_Raw_{{ ps.suffix }}(GP_Context *context, GP_Coord x,
GP_Coord y0, GP_Coord y1, GP_Pixel pixel)
{
@@ -39,6 +18,3 @@ void GP_VLine_Raw_{{ ps.suffix }}(GP_Context *context, GP_Coord x,
GP_PutPixel_Raw_{{ ps.suffix }}(context, x, y, pixel);
}
-%% endfor
-
-{% endblock body %}
diff --git a/libs/gfx/GP_VLineAA.gen.c.t b/libs/gfx/GP_VLineAA.gen.c.t
index 7c5f3fb4..7ddd7cef 100644
--- a/libs/gfx/GP_VLineAA.gen.c.t
+++ b/libs/gfx/GP_VLineAA.gen.c.t
@@ -20,11 +20,7 @@
* *
*****************************************************************************/
-%% extends "base.c.t"
-
-{% block descr %}Anti Aliased Vertical Line{% endblock %}
-
-%% block body
+/* Anti Aliased Vertical Line */
#include "core/GP_Context.h"
#include "core/GP_MixPixels.h"
@@ -79,5 +75,3 @@ void GP_VLineAA_Raw(GP_Context *context, GP_Coord x, GP_Coord y0,
GP_MixPixel_Raw_Clipped(context, int_x+1, y, pixel, lp);
}
}
-
-%% endblock body
diff --git a/libs/gfx/Makefile b/libs/gfx/Makefile
index 8ffe38a0..b76fe13c 100644
--- a/libs/gfx/Makefile
+++ b/libs/gfx/Makefile
@@ -7,6 +7,6 @@ GENSOURCES=GP_Line.gen.c GP_HLine.gen.c GP_LineAA.gen.c GP_PutPixelAA.gen.c GP_FillEllipse.gen.c
LIBNAME=gfx
-include $(TOPDIR)/gen.mk
+include $(TOPDIR)/genn.mk
include $(TOPDIR)/lib.mk
include $(TOPDIR)/post.mk
diff --git a/libs/text/GP_Text.gen.c.t b/libs/text/GP_Text.gen.c.t
index b15d33ac..6a034864 100644
--- a/libs/text/GP_Text.gen.c.t
+++ b/libs/text/GP_Text.gen.c.t
@@ -1,33 +1,11 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2011 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
- * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.c.t"
-
-{% block descr %}Text rendering rutines{% endblock %}
-
-%% block body
+@ include source.t
+/*
+ * Text rendering rutines.
+ *
+ * Copyright (C) 2009-2011 Jiri "BlueBear" Dluhos
+ * <jiri.bluebear.dluhos(a)gmail.com>
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include "core/GP_GetPutPixel.h"
#include "core/GP_MixPixels.gen.h"
@@ -42,8 +20,8 @@ static int get_width(GP_TextStyle *style, int width)
return width * style->pixel_xmul + (width - 1) * style->pixel_xspace;
}
-%% for pt in pixeltypes
-%% if not pt.is_unknown()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown():
static void text_draw_1BPP_{{ pt.name }}(GP_Context *context, GP_TextStyle *style,
GP_Coord x, GP_Coord y,
@@ -95,26 +73,24 @@ static void text_draw_1BPP_{{ pt.name }}(GP_Context *context, GP_TextStyle *styl
}
}
-%% endif
-%% endfor
+@ end
static void text_draw_1BPP(GP_Context *context, GP_TextStyle *style, int x, int y,
GP_Pixel fg, const char *str)
{
switch (context->pixel_type) {
-%% for pt in pixeltypes
-%% if not pt.is_unknown()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown():
case GP_PIXEL_{{ pt.name }}:
text_draw_1BPP_{{ pt.name }}(context, style, x, y, fg, str);
break;
-%% endif
-%% endfor
+@ end
default:
GP_ABORT("Invalid context->pixel_type");
}
}
-%% macro text_8BPP(pt, use_bg)
+@ def text_8BPP(pt, use_bg):
const char *p;
GP_Coord y0 = y;
@@ -147,10 +123,10 @@ static void text_draw_1BPP(GP_Context *context, GP_TextStyle *style, int x, int
int cur_y = y - (glyph->bearing_y - style->font->ascend) * y_mul;
for (k = 0; k < style->pixel_ymul; k++) {
-%% if use_bg
+@ if use_bg:
GP_HLine(context, x_start, x_start + style->pixel_xmul - 1, cur_y + k,
GP_MIX_PIXELS_{{ pt.name }}(fg, bg, gray));
-%% else
+@ else:
unsigned int l;
for (l = x_start; l < x_start + style->pixel_xmul; l++) {
@@ -160,7 +136,7 @@ static void text_draw_1BPP(GP_Context *context, GP_TextStyle *style, int x, int
GP_TRANSFORM_POINT(context, px, py);
GP_MixPixel_Raw_Clipped_{{ pt.name }}(context, px, py, fg, gray);
}
-%% endif
+@ end
}
}
@@ -172,40 +148,38 @@ static void text_draw_1BPP(GP_Context *context, GP_TextStyle *style, int x, int
if (p == str)
x -= get_width(style, glyph->bearing_x);
}
-%% endmacro
-
-%% for pt in pixeltypes
-%% if not pt.is_unknown()
+@ end
+@
+@ for pt in pixeltypes:
+@ if not pt.is_unknown():
static void text_8BPP_bg_{{ pt.name }}(GP_Context *context, GP_TextStyle *style,
GP_Coord x, GP_Coord y,
GP_Pixel fg, GP_Pixel bg, const char *str)
{
-{{ text_8BPP(pt, True) }}
+@ text_8BPP(pt, True)
}
static void text_8BPP_{{ pt.name }}(GP_Context *context, GP_TextStyle *style,
GP_Coord x, GP_Coord y,
GP_Pixel fg, const char *str)
{
-{{ text_8BPP(pt, False) }}
+@ text_8BPP(pt, False)
}
-%% endif
-%% endfor
+@ end
static void text_8BPP_bg(GP_Context *context, GP_TextStyle *style,
GP_Coord x, GP_Coord y,
GP_Pixel fg, GP_Pixel bg, const char *str)
{
switch (context->pixel_type) {
-%% for pt in pixeltypes
-%% if not pt.is_unknown()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown():
case GP_PIXEL_{{ pt.name }}:
text_8BPP_bg_{{ pt.name }}(context, style, x, y, fg, bg, str);
break;
-%% endif
-%% endfor
+@ end
default:
GP_ABORT("Invalid context->pixel_type");
}
@@ -216,13 +190,12 @@ static void text_8BPP(GP_Context *context, GP_TextStyle *style,
GP_Pixel fg, const char *str)
{
switch (context->pixel_type) {
-%% for pt in pixeltypes
-%% if not pt.is_unknown()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown():
case GP_PIXEL_{{ pt.name }}:
text_8BPP_{{ pt.name }}(context, style, x, y, fg, str);
break;
-%% endif
-%% endfor
+@ end
default:
GP_ABORT("Invalid context->pixel_type");
}
@@ -246,5 +219,3 @@ void GP_Text_Raw(GP_Context *context, GP_TextStyle *style,
GP_ABORT("Invalid font glyph bitmap format");
}
}
-
-%% endblock body
diff --git a/libs/text/Makefile b/libs/text/Makefile
index ed33ab79..a02d86a8 100644
--- a/libs/text/Makefile
+++ b/libs/text/Makefile
@@ -6,7 +6,7 @@ GENSOURCES=GP_Text.gen.c
CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c))
LIBNAME=text
-include $(TOPDIR)/gen.mk
+include $(TOPDIR)/genn.mk
include $(TOPDIR)/lib.mk
include $(TOPDIR)/post.mk
diff --git a/tests/core/BlitConv.gen.c.t b/tests/core/BlitConv.gen.c.t
index 05be76a3..97375a8f 100644
--- a/tests/core/BlitConv.gen.c.t
+++ b/tests/core/BlitConv.gen.c.t
@@ -1,30 +1,9 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.test.c.t"
-
-{% block descr %}Blit conversions tests.{% endblock %}
-
-%% block body
+@ include source.t
+/*
+ * Blit conversions tests.
+ *
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include <stdio.h>
@@ -83,7 +62,7 @@ static GP_Pixel rgb_to_pixel(int r, int g, int b, GP_Context *c)
return GP_RGBToContextPixel(r, g, b, c);
}
-%% macro gen_blit(name, r, g, b, pt1, pt2)
+@ def gen_blit(name, r, g, b, pt1, pt2):
static int blit_{{ name }}_{{ pt1.name }}_to_{{ pt2.name }}(void)
{
GP_Context *src = GP_ContextAlloc(100, 100, GP_PIXEL_{{ pt1.name }});
@@ -112,87 +91,70 @@ static int blit_{{ name }}_{{ pt1.name }}_to_{{ pt2.name }}(void)
return TST_SUCCESS;
}
-%% endmacro
-
-%% macro blit_color(name, r, g, b)
-%% for pt1 in pixeltypes
-%% if not pt1.is_unknown() and not pt1.is_palette()
-%% for pt2 in pixeltypes
-%% if not pt2.is_unknown() and not pt2.is_palette()
-{{ gen_blit(name, r, g, b, pt1, pt2) }}
-%% endif
-%% endfor
-%% endif
-%% endfor
-%% endmacro
-
-{{ blit_color('black', '0x00', '0x00', '0x00') }}
-{{ blit_color('white', '0xff', '0xff', '0xff') }}
-
-%% macro blit_equal_pixel(name, r, g, b)
-%% for pt1 in pixeltypes
-%% if not pt1.is_unknown() and not pt1.is_palette()
-{{ gen_blit(name, r, g, b, pt1, pt1) }}
-%% endif
-%% endfor
-%% endmacro
-
-{{ blit_equal_pixel('equal_pixel', '0x0f', '0xff', '0x00') }}
-
-%% macro gen_blit2(name, r, g, b, pname1, pname2)
-{{ gen_blit(name, r, g, b, pixeltypes_dict[pname1], pixeltypes_dict[pname2]) }}
-%% endmacro
-
-{{ gen_blit2('red', '0xff', '0x00', '0x00', 'RGB888', 'CMYK8888') }}
-{{ gen_blit2('green', '0x00', '0xff', '0x00', 'RGB888', 'CMYK8888') }}
-{{ gen_blit2('blue', '0x00', '0x00', '0xff', 'RGB888', 'CMYK8888') }}
-{{ gen_blit2('gray', '0xef', '0xef', '0xef', 'RGB888', 'CMYK8888') }}
-
-{{ gen_blit2('red', '0xff', '0x00', '0x00', 'CMYK8888', 'RGB888') }}
-{{ gen_blit2('green', '0x00', '0xff', '0x00', 'CMYK8888', 'RGB888') }}
-{{ gen_blit2('blue', '0x00', '0x00', '0xff', 'CMYK8888', 'RGB888') }}
-{{ gen_blit2('gray', '0xef', '0xef', '0xef', 'CMYK8888', 'RGB888') }}
-
-
-%% macro gen_suite_entry(name, from, to)
- {.name = "Blit {{ from }} to {{ to }}",
- .tst_fn = blit_{{ name }}_{{ from }}_to_{{ to }}},
-%% endmacro
+
+@ def blit_color(name, r, g, b):
+@ for pt1 in pixeltypes:
+@ if not pt1.is_unknown() and not pt1.is_palette():
+@ for pt2 in pixeltypes:
+@ if not pt2.is_unknown() and not pt2.is_palette():
+{@ gen_blit(name, r, g, b, pt1, pt2) @}
+@ end
+@
+{@ blit_color('black', '0x00', '0x00', '0x00') @}
+{@ blit_color('white', '0xff', '0xff', '0xff') @}
+
+@ def blit_equal_pixel(name, r, g, b):
+@ for pt1 in pixeltypes:
+@ if not pt1.is_unknown() and not pt1.is_palette():
+{@ gen_blit(name, r, g, b, pt1, pt1) @}
+@ end
+@
+{@ blit_equal_pixel('equal_pixel', '0x0f', '0xff', '0x00') @}
+
+@ def gen_blit2(name, r, g, b, pname1, pname2):
+{@ gen_blit(name, r, g, b, pixeltypes_dict[pname1], pixeltypes_dict[pname2]) @}
+@ end
+
+{@ gen_blit2('red', '0xff', '0x00', '0x00', 'RGB888', 'CMYK8888') @}
+{@ gen_blit2('green', '0x00', '0xff', '0x00', 'RGB888', 'CMYK8888') @}
+{@ gen_blit2('blue', '0x00', '0x00', '0xff', 'RGB888', 'CMYK8888') @}
+{@ gen_blit2('gray', '0xef', '0xef', '0xef', 'RGB888', 'CMYK8888') @}
+{@ gen_blit2('red', '0xff', '0x00', '0x00', 'CMYK8888', 'RGB888') @}
+{@ gen_blit2('green', '0x00', '0xff', '0x00', 'CMYK8888', 'RGB888') @}
+{@ gen_blit2('blue', '0x00', '0x00', '0xff', 'CMYK8888', 'RGB888') @}
+{@ gen_blit2('gray', '0xef', '0xef', '0xef', 'CMYK8888', 'RGB888') @}
+
+@ def gen_suite_entry(name, p_from, p_to):
+ {.name = "Blit {{ p_from }} to {{ p_to }}",
+ .tst_fn = blit_{{ name }}_{{ p_from }}_to_{{ p_to }}},
+@ end
const struct tst_suite tst_suite = {
.suite_name = "Blit Conversions Testsuite",
.tests = {
-%% for pt1 in pixeltypes
-%% if not pt1.is_unknown() and not pt1.is_palette()
-%% for pt2 in pixeltypes
-%% if not pt2.is_unknown() and not pt2.is_palette()
- {.name = "Blit black {{ pt1.name }} to {{ pt2.name }}",
+@ for pt1 in pixeltypes:
+@ if not pt1.is_unknown() and not pt1.is_palette():
+@ for pt2 in pixeltypes:
+@ if not pt2.is_unknown() and not pt2.is_palette():
+ {.name = "Blit black {{ pt1.name }} to {{ pt2.name }}",
.tst_fn = blit_black_{{ pt1.name }}_to_{{ pt2.name }}},
- {.name = "Blit white {{ pt1.name }} to {{ pt2.name }}",
+ {.name = "Blit white {{ pt1.name }} to {{ pt2.name }}",
.tst_fn = blit_white_{{ pt1.name }}_to_{{ pt2.name }}},
-%% endif
-%% endfor
-%% endif
-%% endfor
-%% for pt1 in pixeltypes
-%% if not pt1.is_unknown() and not pt1.is_palette()
- {.name = "Blit {{ pt1.name }} to {{ pt1.name }}",
+@ for pt1 in pixeltypes:
+@ if not pt1.is_unknown() and not pt1.is_palette():
+ {.name = "Blit {{ pt1.name }} to {{ pt1.name }}",
.tst_fn = blit_equal_pixel_{{ pt1.name }}_to_{{ pt1.name }}},
-%% endif
-%% endfor
-
-{{ gen_suite_entry('red', 'RGB888', 'CMYK8888') }}
-{{ gen_suite_entry('green', 'RGB888', 'CMYK8888') }}
-{{ gen_suite_entry('blue', 'RGB888', 'CMYK8888') }}
-{{ gen_suite_entry('gray', 'RGB888', 'CMYK8888') }}
+@ end
-{{ gen_suite_entry('red', 'CMYK8888', 'RGB888') }}
-{{ gen_suite_entry('green', 'CMYK8888', 'RGB888') }}
-{{ gen_suite_entry('blue', 'CMYK8888', 'RGB888') }}
-{{ gen_suite_entry('gray', 'CMYK8888', 'RGB888') }}
+{@ gen_suite_entry('red', 'RGB888', 'CMYK8888') @}
+{@ gen_suite_entry('green', 'RGB888', 'CMYK8888') @}
+{@ gen_suite_entry('blue', 'RGB888', 'CMYK8888') @}
+{@ gen_suite_entry('gray', 'RGB888', 'CMYK8888') @}
+{@ gen_suite_entry('red', 'CMYK8888', 'RGB888') @}
+{@ gen_suite_entry('green', 'CMYK8888', 'RGB888') @}
+{@ gen_suite_entry('blue', 'CMYK8888', 'RGB888') @}
+{@ gen_suite_entry('gray', 'CMYK8888', 'RGB888') @}
{.name = NULL}
}
};
-
-%% endblock body
diff --git a/tests/core/Convert.gen.c.t b/tests/core/Convert.gen.c.t
index 945903ae..362d765a 100644
--- a/tests/core/Convert.gen.c.t
+++ b/tests/core/Convert.gen.c.t
@@ -1,33 +1,10 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.test.c.t"
-
-{% block descr %}Pixel conversions tests.{% endblock %}
-
-%% block body
-
+@ include source.t
+/*
+ * Pixel conversions tests.
+ *
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include <stdio.h>
-
#include <core/GP_Convert.h>
#include "tst_test.h"
@@ -38,20 +15,19 @@
static GP_Pixel get_black(GP_PixelType pixel_type)
{
switch (pixel_type) {
-%% for pt in pixeltypes
+@ for pt in pixeltypes:
case {{ pt.C_type }}:
-%% if pt.is_cmyk()
-%% set K = pt.chans['K']
+@ if pt.is_cmyk():
+@ K = pt.chans['K']
/* Black in CMYK is full K rest zero */
return {{ K.C_mask }};
-%% elif pt.is_alpha()
-%% set A = pt.chans['A']
+@ elif pt.is_alpha():
+@ A = pt.chans['A']
/* Black with Alpha channel is full A rest zero */
return {{ A.C_mask }};
-%% else
+@ else:
return 0;
-%% endif
-%% endfor
+@ end
default:
tst_msg("Invalid pixel type %i", pixel_type);
exit(TST_INTERR);
@@ -64,39 +40,38 @@ static GP_Pixel get_black(GP_PixelType pixel_type)
static GP_Pixel get_white(GP_PixelType pixel_type)
{
switch (pixel_type) {
-%% for pt in pixeltypes
+@ for pt in pixeltypes:
case {{ pt.C_type }}:
-%% if pt.is_cmyk()
+@ if pt.is_cmyk():
/* White in CMYK is zero */
return 0x0;
-%% elif pt.is_rgb()
-%% set R = pt.chans['R']
-%% set G = pt.chans['G']
-%% set B = pt.chans['B']
-%% if pt.is_alpha()
-%% set A = pt.chans['A']
+@ elif pt.is_rgb():
+@ R = pt.chans['R']
+@ G = pt.chans['G']
+@ B = pt.chans['B']
+@ if pt.is_alpha():
+@ A = pt.chans['A']
/* White in RGBA */
return {{ A.C_mask }} | {{ R.C_mask }} | {{ G.C_mask }} | {{ B.C_mask }};
-%% else
+@ else:
/* Plain old RGB */
return {{ R.C_mask }} | {{ G.C_mask }} | {{ B.C_mask }};
-%% endif
-%% elif pt.is_gray()
-%% set V = pt.chans['V']
-%% if pt.is_alpha()
-%% set A = pt.chans['A']
+@ end
+@ elif pt.is_gray():
+@ V = pt.chans['V']
+@ if pt.is_alpha():
+@ A = pt.chans['A']
/* Grayscale with Alpha */
return {{ V.C_mask }} | {{ A.C_mask }};
-%% else
+@ else:
/* Grayscale */
return {{ V.C_mask }};
-%% endif
-%% else
+@ end
+@ else:
tst_msg("FIXME: Unsupported conversion to %s",
GP_PixelTypeName(pixel_type));
exit(TST_INTERR);
-%% endif
-%% endfor
+@ end
default:
tst_msg("Invalid pixel type %i", pixel_type);
exit(TST_INTERR);
@@ -109,46 +84,45 @@ static GP_Pixel get_white(GP_PixelType pixel_type)
static GP_Pixel get_red(GP_PixelType pixel_type)
{
switch (pixel_type) {
-%% for pt in pixeltypes
+@ for pt in pixeltypes:
case {{ pt.C_type }}:
-%% if pt.is_cmyk()
-%% set M = pt.chans['M']
-%% set Y = pt.chans['Y']
+@ if pt.is_cmyk():
+@ M = pt.chans['M']
+@ Y = pt.chans['Y']
/* Red in CMYK is full M and Y rest zero */
return {{ M.C_mask }} | {{ Y.C_mask }};
-%% elif pt.is_rgb()
-%% set R = pt.chans['R']
-%% if pt.is_alpha()
-%% set A = pt.chans['A']
+@ elif pt.is_rgb():
+@ R = pt.chans['R']
+@ if pt.is_alpha():
+@ A = pt.chans['A']
/* Red with Alpha channel is full Alpha and R rest zero */
return {{ A.C_mask }} | {{ R.C_mask }};
-%% else
+@ else:
/* Plain old RGB */
return {{ R.C_mask }};
-%% endif
-%% elif pt.is_gray()
-%% set V = pt.chans['V']
-%% if pt.is_alpha()
-%% set A = pt.chans['A']
+@ end
+@ elif pt.is_gray():
+@ V = pt.chans['V']
+@ if pt.is_alpha():
+@ A = pt.chans['A']
/* Grayscale with Alpha channel is full Alpha + 1/3 Gray */
return ({{ hex(V.max // 3)}}{{ V.C_shift }}) | {{ A.C_mask }};
-%% else
+@ else:
/* Grayscale is 1/3 Gray */
return {{ hex(V.max // 3) }}{{ V.C_shift }};
-%% endif
-%% else
+@ end
+@ else:
tst_msg("FIXME: Unsupported conversion to %s",
GP_PixelTypeName(pixel_type));
exit(TST_INTERR);
-%% endif
-%% endfor
+@ end
default:
tst_msg("Invalid pixel type %i", pixel_type);
exit(TST_INTERR);
}
}
-%% macro gen_convert_and_check(test_name, in_name, out_name)
+@ def gen_convert_and_check(test_name, in_name, out_name):
static int convert_and_check_{{ test_name }}_{{ in_name }}_to_{{ out_name }}(void)
{
GP_Pixel out = 0;
@@ -167,69 +141,63 @@ static int convert_and_check_{{ test_name }}_{{ in_name }}_to_{{ out_name }}(voi
return TST_SUCCESS;
}
-%% endmacro
-
-%% macro gen_converts()
-%% for pt1 in pixeltypes
-%% if not pt1.is_unknown() and not pt1.is_palette()
-%% if pt1.name not in ['RGB888', 'RGBA8888']
-{#- White -#}
-{{ gen_convert_and_check('white', pt1.name, 'RGB888') }}
-{{ gen_convert_and_check('white', pt1.name, 'RGBA8888') }}
-{{ gen_convert_and_check('white', 'RGB888', pt1.name) }}
-{{ gen_convert_and_check('white', 'RGBA8888', pt1.name) }}
-{#- Black -#}
-{{ gen_convert_and_check('black', pt1.name, 'RGB888') }}
-{{ gen_convert_and_check('black', pt1.name, 'RGBA8888') }}
-{{ gen_convert_and_check('black', 'RGB888', pt1.name) }}
-{{ gen_convert_and_check('black', 'RGBA8888', pt1.name) }}
-{#- Red -#}
-%% if not pt1.is_gray()
-{{ gen_convert_and_check('red', pt1.name, 'RGB888') }}
-{{ gen_convert_and_check('red', pt1.name, 'RGBA8888') }}
-%% endif
-{{ gen_convert_and_check('red', 'RGB888', pt1.name) }}
-{{ gen_convert_and_check('red', 'RGBA8888', pt1.name) }}
-%% endif
-%% endif
-%% endfor
-%% endmacro
-{{ gen_converts() }}
-
-%% macro gen_suite_entry(name, from, to)
- {.name = "Convert {{ name }} {{ from }} -> {{ to }}",
- .tst_fn = convert_and_check_{{ name }}_{{ from }}_to_{{ to }}},
-%% endmacro
+@ end
+@
+@ def gen_converts():
+@ for pt1 in pixeltypes:
+@ if not pt1.is_unknown() and not pt1.is_palette():
+@ if pt1.name not in ['RGB888', 'RGBA8888']:
+@ # White
+{@ gen_convert_and_check('white', pt1.name, 'RGB888') @}
+{@ gen_convert_and_check('white', pt1.name, 'RGBA8888') @}
+{@ gen_convert_and_check('white', 'RGB888', pt1.name) @}
+{@ gen_convert_and_check('white', 'RGBA8888', pt1.name) @}
+@ # Black
+{@ gen_convert_and_check('black', pt1.name, 'RGB888') @}
+{@ gen_convert_and_check('black', pt1.name, 'RGBA8888') @}
+{@ gen_convert_and_check('black', 'RGB888', pt1.name) @}
+{@ gen_convert_and_check('black', 'RGBA8888', pt1.name) @}
+@ # Red
+@ if not pt1.is_gray():
+{@ gen_convert_and_check('red', pt1.name, 'RGB888') @}
+{@ gen_convert_and_check('red', pt1.name, 'RGBA8888') @}
+@ end
+{@ gen_convert_and_check('red', 'RGB888', pt1.name) @}
+{@ gen_convert_and_check('red', 'RGBA8888', pt1.name) @}
+@ end
+@
+{@ gen_converts() @}
+
+@ def gen_suite_entry(name, p_from, p_to):
+ {.name = "Convert {{ name }} {{ p_from }} -> {{ p_to }}",
+ .tst_fn = convert_and_check_{{ name }}_{{ p_from }}_to_{{ p_to }}},
+@ end
const struct tst_suite tst_suite = {
.suite_name = "Pixel Conversions Testsuite",
.tests = {
-%% for pt1 in pixeltypes
-%% if not pt1.is_unknown() and not pt1.is_palette()
-%% if pt1.name not in ['RGB888', 'RGBA8888']
-{#- White -#}
-{{ gen_suite_entry('white', pt1.name, 'RGB888') }}
-{{ gen_suite_entry('white', pt1.name, 'RGBA8888') }}
-{{ gen_suite_entry('white', 'RGB888', pt1.name) }}
-{{ gen_suite_entry('white', 'RGBA8888', pt1.name) }}
-{#- Black -#}
-{{ gen_suite_entry('black', pt1.name, 'RGB888') }}
-{{ gen_suite_entry('black', pt1.name, 'RGBA8888') }}
-{{ gen_suite_entry('black', 'RGB888', pt1.name) }}
-{{ gen_suite_entry('black', 'RGBA8888', pt1.name) }}
-{#- Red -#}
-%% if not pt1.is_gray()
-{{ gen_suite_entry('red', pt1.name, 'RGB888') }}
-{{ gen_suite_entry('red', pt1.name, 'RGBA8888') }}
-%% endif
-{{ gen_suite_entry('red', 'RGB888', pt1.name) }}
-{{ gen_suite_entry('red', 'RGBA8888', pt1.name) }}
-%% endif
-%% endif
-%% endfor
+@ for pt1 in pixeltypes:
+@ if not pt1.is_unknown() and not pt1.is_palette():
+@ if pt1.name not in ['RGB888', 'RGBA8888']:
+@ # White
+{@ gen_suite_entry('white', pt1.name, 'RGB888') @}
+{@ gen_suite_entry('white', pt1.name, 'RGBA8888') @}
+{@ gen_suite_entry('white', 'RGB888', pt1.name) @}
+{@ gen_suite_entry('white', 'RGBA8888', pt1.name) @}
+@ # Black
+{@ gen_suite_entry('black', pt1.name, 'RGB888') @}
+{@ gen_suite_entry('black', pt1.name, 'RGBA8888') @}
+{@ gen_suite_entry('black', 'RGB888', pt1.name) @}
+{@ gen_suite_entry('black', 'RGBA8888', pt1.name) @}
+@ # Red
+@ if not pt1.is_gray():
+{@ gen_suite_entry('red', pt1.name, 'RGB888') @}
+{@ gen_suite_entry('red', pt1.name, 'RGBA8888') @}
+@ end
+{@ gen_suite_entry('red', 'RGB888', pt1.name) @}
+{@ gen_suite_entry('red', 'RGBA8888', pt1.name) @}
+@ end
{.name = NULL}
}
};
-
-%% endblock body
diff --git a/tests/core/Convert_Scale.gen.c.t b/tests/core/Convert_Scale.gen.c.t
index 2da4e03c..85f86b3a 100644
--- a/tests/core/Convert_Scale.gen.c.t
+++ b/tests/core/Convert_Scale.gen.c.t
@@ -1,30 +1,9 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.test.c.t"
-
-{% block descr %}ConvertScale tests.{% endblock %}
-
-%% block body
+@ include source.t
+/*
+ * ConvertScale tests.
+ *
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include <stdio.h>
#include <math.h>
@@ -34,11 +13,11 @@
#include "tst_test.h"
-%% set max_in = 24
-%% set max_out = 16
-
-%% for i in range(1, max_in)
-%% for j in range(1, max_out)
+@ max_in = 24
+@ max_out = 16
+@
+@ for i in range(1, max_in):
+@ for j in range(1, max_out):
static int check_convert_{{ i }}_{{ j }}(void)
{
unsigned int v, fail = 0;
@@ -47,7 +26,7 @@ static int check_convert_{{ i }}_{{ j }}(void)
for (v = 0; v < {{ 2 ** i - 1 }}; v++) {
res = GP_SCALE_VAL_{{ i }}_{{ j }}(v);
-%% if j > i
+@ if j > i:
/*
* We have {{ 2**i }} values and we need to map them to
* subset of {{ 2**j }} values while making sure 0 -> 0
@@ -60,7 +39,7 @@ static int check_convert_{{ i }}_{{ j }}(void)
*/
fres = (v / {{ (2.00 ** i - 1) }}) * {{ (2.00 ** j - 1) }};
exp_res = round(fres);
-%% else
+@ else:
/*
* We have {{ 2**i }} values that must be mapped to {{ 2**j }}
* so we do simple division and floor() which maps the values
@@ -70,7 +49,7 @@ static int check_convert_{{ i }}_{{ j }}(void)
*/
fres = v * {{ (2.00 ** j) / (2.00 ** i) }};
exp_res = floor(fres);
-%% endif
+@ end
if (res != exp_res) {
if (fail < 5)
@@ -89,20 +68,16 @@ static int check_convert_{{ i }}_{{ j }}(void)
return TST_SUCCESS;
}
-%% endfor
-%% endfor
-
+@ endfor
+@
const struct tst_suite tst_suite = {
.suite_name = "Convert Scale Testsuite",
.tests = {
-%% for i in range(1, max_in)
-%% for j in range(1, max_out)
+@ for i in range(1, max_in):
+@ for j in range(1, max_out):
{.name = "SCALE_{{ i }}_{{ j }}()",
.tst_fn = check_convert_{{ i }}_{{ j }}},
-%% endfor
-%% endfor
+@ end
{.name = NULL}
}
};
-
-%% endblock body
diff --git a/tests/core/GetPutPixel.gen.c.t b/tests/core/GetPutPixel.gen.c.t
index 1e8bccde..4f2c2157 100644
--- a/tests/core/GetPutPixel.gen.c.t
+++ b/tests/core/GetPutPixel.gen.c.t
@@ -1,30 +1,9 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.test.c.t"
-
-{% block descr %}GetPutPixel tests.{% endblock %}
-
-%% block body
+@ include source.t
+/*
+ * GetPutPixel tests.
+ *
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include <stdio.h>
@@ -71,8 +50,8 @@ static int try_pattern(GP_Context *c, GP_Pixel p)
return 0;
}
-%% for pt in pixeltypes
-%% if not pt.is_unknown()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown():
static int GetPutPixel_{{ pt.name }}(void)
{
GP_Context *c;
@@ -104,11 +83,10 @@ static int GetPutPixel_{{ pt.name }}(void)
return TST_SUCCESS;
}
-%% endif
-%% endfor
+@ end
-%% for pt in pixeltypes
-%% if not pt.is_unknown()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown():
static int GetPutPixel_Clipping_{{ pt.name }}(void)
{
GP_Context *c;
@@ -149,28 +127,23 @@ static int GetPutPixel_Clipping_{{ pt.name }}(void)
return TST_SUCCESS;
}
-%% endif
-%% endfor
+@ end
const struct tst_suite tst_suite = {
.suite_name = "GetPutPixel Testsuite",
.tests = {
-%% for pt in pixeltypes
-%% if not pt.is_unknown()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown():
{.name = "GetPutPixel {{ pt.name }}",
.tst_fn = GetPutPixel_{{ pt.name }}},
-%% endif
-%% endfor
+@ end
-%% for pt in pixeltypes
-%% if not pt.is_unknown()
+@ for pt in pixeltypes:
+@ if not pt.is_unknown():
{.name = "GetPutPixel Clipping {{ pt.name }}",
.tst_fn = GetPutPixel_Clipping_{{ pt.name }}},
-%% endif
-%% endfor
+@ end
{.name = NULL}
}
};
-
-%% endblock body
diff --git a/tests/core/GetSetBits.gen.c.t b/tests/core/GetSetBits.gen.c.t
index 5c33f89b..475c83a9 100644
--- a/tests/core/GetSetBits.gen.c.t
+++ b/tests/core/GetSetBits.gen.c.t
@@ -1,30 +1,9 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.test.c.t"
-
-{% block descr %}GP_GET_BITS() and GP_SET_BITS() tests.{% endblock %}
-
-%% block body
+@ include source.t
+/*
+ * GP_GET_BITS() and GP_SET_BITS() tests.
+ *
+ * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include <stdlib.h>
#include <stdint.h>
@@ -40,8 +19,8 @@ static const uint32_t patterns[] = {
0x43f8af32,
};
-%% for len in range(1, 33)
-%% for off in range(0, 33 - len)
+@ for len in range(1, 33):
+@ for off in range(0, 33 - len):
static int getbits_{{ off }}_{{ len }}(void)
{
uint32_t p_exp, p_get;
@@ -65,15 +44,11 @@ static int getbits_{{ off }}_{{ len }}(void)
return TST_SUCCESS;
}
-%% endfor
-%% endfor
-%% macro mask(off, len)
-~{{ hex((2 ** len - 1) * (2 ** off)) }}
-%%- endmacro
-
-%% for len in range(1, 33)
-%% for off in range(0, 33 - len)
+@ end
+@
+@ for len in range(1, 33):
+@ for off in range(0, 33 - len):
static int setbits_{{ off }}_{{ len }}(void)
{
uint32_t p_exp, canary1, p_get, canary2, val;
@@ -81,7 +56,7 @@ static int setbits_{{ off }}_{{ len }}(void)
for (i = 0; i < GP_ARRAY_SIZE(patterns); i++) {
for (j = 0; j < GP_ARRAY_SIZE(patterns); j++) {
- {# GP_SET_BITS() needs value clamped to the len #}
+@ # GP_SET_BITS() needs value clamped to the len
val = patterns[j] & {{ hex(2 ** len - 1) }};
canary1 = 0;
@@ -89,7 +64,7 @@ static int setbits_{{ off }}_{{ len }}(void)
p_get = patterns[i];
GP_SET_BITS({{ off }}, {{ len }}, p_get, val);
- p_exp = patterns[i] & {{ mask(off, len) }};
+ p_exp = patterns[i] & ~{{ hex((2 ** len - 1) * (2 ** off)) }};
p_exp |= val<<{{ off }};
if (p_get != p_exp || canary1 != 0 || canary2 != 0) {
@@ -105,26 +80,22 @@ static int setbits_{{ off }}_{{ len }}(void)
return TST_SUCCESS;
}
-%% endfor
-%% endfor
+@ end
+@
const struct tst_suite tst_suite = {
.suite_name = "GetSetBits testsuite",
.tests = {
-%% for len in range(1, 33)
-%% for off in range(0, 33 - len)
+@ for len in range(1, 33):
+@ for off in range(0, 33 - len):
{.name = "GP_GET_BITS off={{ off }} len={{ len }}",
.tst_fn = getbits_{{ off }}_{{ len }}},
-%% endfor
-%% endfor
-%% for len in range(1, 33)
-%% for off in range(0, 33 - len)
+@ end
+@ for len in range(1, 33):
+@ for off in range(0, 33 - len):
{.name = "GP_SET_BITS off={{ off }} len={{ len }}",
.tst_fn = setbits_{{ off }}_{{ len }}},
-%% endfor
-%% endfor
+@ end
{.name = NULL}
}
};
-
-%% endblock body
diff --git a/tests/core/Makefile b/tests/core/Makefile
index 737fc17f..cfb3a543 100644
--- a/tests/core/Makefile
+++ b/tests/core/Makefile
@@ -12,6 +12,6 @@ APPS=WritePixel.gen Pixel Context GetPutPixel.gen Convert.gen BlitConv.gen
include ../tests.mk
-include $(TOPDIR)/gen.mk
+include $(TOPDIR)/genn.mk
include $(TOPDIR)/app.mk
include $(TOPDIR)/post.mk
diff --git a/tests/core/WritePixel.gen.c.t b/tests/core/WritePixel.gen.c.t
index 9c433a0f..094c4438 100644
--- a/tests/core/WritePixel.gen.c.t
+++ b/tests/core/WritePixel.gen.c.t
@@ -1,30 +1,8 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends "base.test.c.t"
-
-{% block descr %}WritePixel tests.{% endblock %}
-
-%% block body
+/*
+ * WritePixel tests.
+ *
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include <stdio.h>
#include <string.h>
@@ -73,12 +51,12 @@ static void dump_buffer(const char *name, char *buf, unsigned int buf_len)
return TST_SUCCESS; } while (0)
-%% for pixelsize in [8, 16, 24, 32]
-%% for offset in range(0, 4)
-%% for len in range(0, 6)
-%% for aligment in [0, 4]
-%% if (pixelsize != 16 and pixelsize != 32) or aligment == 0
-static int WritePixel{{ "_%i_%i_%i_%i"|format(pixelsize, offset, len, aligment) }}(void)
+@ for pixelsize in [8, 16, 24, 32]:
+@ for offset in range(0, 4):
+@ for len in range(0, 6):
+@ for aligment in [0, 4]:
+@ if (pixelsize != 16 and pixelsize != 32) or aligment == 0:
+static int WritePixel{{ "_%i_%i_%i_%i" % (pixelsize, offset, len, aligment) }}(void)
{
char write_buf[{{ 25 * pixelsize//8 }}] = {};
char gen_buf[{{ 25 * pixelsize//8 }}] = {};
@@ -86,18 +64,17 @@ static int WritePixel{{ "_%i_%i_%i_%i"|format(pixelsize, offset, len, aligment)
/*
* Fill the compare buffer
*/
-%% for i in range(0, len)
-%% for j in range(0, pixelsize//8)
+@ for i in range(0, len):
+@ for j in range(0, pixelsize//8):
gen_buf[{{aligment + offset * pixelsize//8 + i * pixelsize//8 + j}}] = 0xff;
-%% endfor
-%% endfor
+@ end
GP_WritePixels_{{ pixelsize }}BPP(write_buf + {{aligment + offset * pixelsize//8}}, {{ len }}, 0xffffffff>>{{32 - pixelsize}});
- COMPARE_BUFFERS({{""p=%i o=%i l=%i a=%i""|format(pixelsize, offset, len, aligment)}}, write_buf, gen_buf);
+ COMPARE_BUFFERS({{'"p=%i o=%i l=%i a=%i"' % (pixelsize, offset, len, aligment)}}, write_buf, gen_buf);
}
-static int WritePixel{{ "_%i_%i_%i_%i_alloc"|format(pixelsize, offset, len, aligment) }}(void)
+static int WritePixel{{ "_%i_%i_%i_%i_alloc" % (pixelsize, offset, len, aligment) }}(void)
{
char gen_buf[{{ 25 * pixelsize//8 }}] = {};
char *write_buf = malloc({{ 25 * pixelsize//8 }});
@@ -105,11 +82,10 @@ static int WritePixel{{ "_%i_%i_%i_%i_alloc"|format(pixelsize, offset, len, alig
/*
* Fill the compare buffer
*/
-%% for i in range(0, len)
-%% for j in range(0, pixelsize//8)
+@ for i in range(0, len):
+@ for j in range(0, pixelsize//8):
gen_buf[{{aligment + offset * pixelsize//8 + i * pixelsize//8 + j}}] = 0xff;
-%% endfor
-%% endfor
+@ end
if (gen_buf == NULL) {
tst_msg("Malloc failed :(");
@@ -120,33 +96,23 @@ static int WritePixel{{ "_%i_%i_%i_%i_alloc"|format(pixelsize, offset, len, alig
GP_WritePixels_{{ pixelsize }}BPP(write_buf + {{aligment + offset * pixelsize//8}}, {{ len }}, 0xffffffff>>{{32 - pixelsize}});
- COMPARE_BUFFERS({{""p=%i o=%i l=%i a=%i""|format(pixelsize, offset, len, aligment)}}, write_buf, gen_buf);
+ COMPARE_BUFFERS({{'"p=%i o=%i l=%i a=%i"' % (pixelsize, offset, len, aligment)}}, write_buf, gen_buf);
}
-%% endif
-%% endfor
-%% endfor
-%% endfor
-%% endfor
+@ end
const struct tst_suite tst_suite = {
.suite_name = "WritePixel Testsuite",
.tests = {
-%% for pixelsize in [8, 16, 24, 32]
-%% for offset in range(0, 4)
-%% for len in range(0, 6)
-%% for aligment in [0, 4]
-%% if (pixelsize != 16 and pixelsize != 32) or aligment == 0
- {.name = "WritePixel {{ pixelsize }} {{ offset }} {{ len }} {{ aligment }} stack",
- .tst_fn = WritePixel{{ "_%i_%i_%i_%i"|format(pixelsize, offset, len, aligment) }}},
- {.name = "WritePixel {{ pixelsize }} {{ offset }} {{ len }} {{ aligment }} alloc",
- .tst_fn = WritePixel{{ "_%i_%i_%i_%i_alloc"|format(pixelsize, offset, len, aligment) }}},
-%% endif
-%% endfor
-%% endfor
-%% endfor
-%% endfor
+@ for pixelsize in [8, 16, 24, 32]:
+@ for offset in range(0, 4):
+@ for len in range(0, 6):
+@ for aligment in [0, 4]:
+@ if (pixelsize != 16 and pixelsize != 32) or aligment == 0:
+ {.name = "WritePixel {{ pixelsize }} {{ offset }} {{ len }} {{ aligment }} stack",
+ .tst_fn = WritePixel{{ "_%i_%i_%i_%i" % (pixelsize, offset, len, aligment) }}},
+ {.name = "WritePixel {{ pixelsize }} {{ offset }} {{ len }} {{ aligment }} alloc",
+ .tst_fn = WritePixel{{ "_%i_%i_%i_%i_alloc" % (pixelsize, offset, len, aligment) }}},
+@ end
{.name = NULL}
}
};
-
-%% endblock body
diff --git a/tests/gfx/APICoverage.gen.c.t b/tests/gfx/APICoverage.gen.c.t
index 1afea7e4..7cccfa00 100644
--- a/tests/gfx/APICoverage.gen.c.t
+++ b/tests/gfx/APICoverage.gen.c.t
@@ -1,37 +1,10 @@
-/*****************************************************************************
- * 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> *
- * *
- *****************************************************************************/
-
- /*
-
- The purpose of this test is to exercise as much codepaths as possible
- without checking for result corectness.
-
- */
-
-%% extends "base.test.c.t"
-
-{% block descr %}GFX API converage tests.{% endblock %}
-
-%% block body
+@ include source.t
+/*
+ * The purpose of this test is to exercise as much codepaths as possible
+ * without checking for result corectness.
+ *
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz>
+ */
#include <stdio.h>
@@ -40,101 +13,95 @@
#include "tst_test.h"
-%% set API_List = [
- ['Fill', 'GP_Context:in', 'int:pixel'],
-
- ['HLine', 'GP_Context:in', 'int:x0', 'int:x1', 'int:y', 'int:pixel'],
- ['VLine', 'GP_Context:in', 'int:x', 'int:y0', 'int:y1', 'int:pixel'],
-
- ['Line', 'GP_Context:in', 'int:x0', 'int:y0',
- 'int:x1', 'int:y1', 'int:pixel'],
-
- ['Circle', 'GP_Context:in', 'int:xcenter', 'int:ycenter',
- 'int:r', 'int:pixel'],
- ['FillCircle', 'GP_Context:in', 'int:xcenter', 'int:ycenter',
- 'int:r', 'int:pixel'],
-
- ['Ellipse', 'GP_Context:in', 'int:xcenter', 'int:ycenter',
- 'int:a', 'int:b', 'int:pixel'],
- ['FillEllipse', 'GP_Context:in', 'int:xcenter', 'int:ycenter',
- 'int:a', 'int:b', 'int:pixel'],
-
- ['Ring', 'GP_Context:in', 'int:xc', 'int:yc',
- 'int:r1', 'int:r2', 'int:pixel'],
- ['FillRing', 'GP_Context:in', 'int:xc', 'int:yc',
- 'int:r1', 'int:r2', 'int:pixel'],
-
- ['Rect', 'GP_Context:in', 'int:x0', 'int:y0',
- 'int:x1', 'int:y1', 'int:pixel'],
- ['FillRect', 'GP_Context:in', 'int:x0', 'int:y0',
- 'int:x1', 'int:y1', 'int:pixel'],
-
- ['Triangle', 'GP_Context:in', 'int:x0', 'int:y0',
- 'int:x1', 'int:y1', 'int:x2', 'int:y2', 'int:pixel'],
- ['FillTriangle', 'GP_Context:in', 'int:x0', 'int:y0',
- 'int:x1', 'int:y1', 'int:x2', 'int:y2', 'int:pixel'],
-
- ['Tetragon', 'GP_Context:in', 'int:x0', 'int:y0', 'int:x1', 'int:y1',
- 'int:x2', 'int:y2', 'int:x3', 'int:y3', 'int:pixel'],
- ['FillTetragon', 'GP_Context:in', 'int:x0', 'int:y0', 'int:x1', 'int:y1',
- 'int:x2', 'int:y2', 'int:x3', 'int:y3', 'int:pixel'],
-
-]
-
-%% macro prep_context(id, pt)
- GP_Context *{{ id }} = GP_ContextAlloc(331, 331, GP_PIXEL_{{ pt.name }});
-%% endmacro
-
-%% macro prep_int(id)
- int {{ id }} = 2;
-%% endmacro
-
-%% macro prep_param(param, pt)
-%% if (param.split(':', 1)[0] == 'GP_Context')
-{{ prep_context(param.split(':', 1)[1], pt) }}
-%% endif
-%% if (param.split(':', 1)[0] == 'float')
-{{ prep_float(param.split(':', 1)[1]) }}
-%% endif
-%% if (param.split(':', 1)[0] == 'int')
-{{ prep_int(param.split(':', 1)[1]) }}
-%% endif
-%% endmacro
-
-{% macro get_param(param) %}{% if len(param.split(':', 1)) == 1 %}NULL{% else %}{{ param.split(':', 1)[1] }}{% endif %}{% endmacro %}
-
-%% for fn in API_List
-%% for pt in pixeltypes
-%% if not pt.is_unknown()
-
+@ API_List = [
+@ ['Fill', 'GP_Context:in', 'int:pixel'],
+@
+@ ['HLine', 'GP_Context:in', 'int:x0', 'int:x1', 'int:y', 'int:pixel'],
+@ ['VLine', 'GP_Context:in', 'int:x', 'int:y0', 'int:y1', 'int:pixel'],
+@
+@ ['Line', 'GP_Context:in', 'int:x0', 'int:y0',
+@ 'int:x1', 'int:y1', 'int:pixel'],
+@
+@ ['Circle', 'GP_Context:in', 'int:xcenter', 'int:ycenter',
+@ 'int:r', 'int:pixel'],
+@ ['FillCircle', 'GP_Context:in', 'int:xcenter', 'int:ycenter',
+@ 'int:r', 'int:pixel'],
+@
+@ ['Ellipse', 'GP_Context:in', 'int:xcenter', 'int:ycenter',
+@ 'int:a', 'int:b', 'int:pixel'],
+@ ['FillEllipse', 'GP_Context:in', 'int:xcenter', 'int:ycenter',
+@ 'int:a', 'int:b', 'int:pixel'],
+@
+@ ['Ring', 'GP_Context:in', 'int:xc', 'int:yc',
+@ 'int:r1', 'int:r2', 'int:pixel'],
+@ ['FillRing', 'GP_Context:in', 'int:xc', 'int:yc',
+@ 'int:r1', 'int:r2', 'int:pixel'],
+@
+@ ['Rect', 'GP_Context:in', 'int:x0', 'int:y0',
+@ 'int:x1', 'int:y1', 'int:pixel'],
+@ ['FillRect', 'GP_Context:in', 'int:x0', 'int:y0',
+@ 'int:x1', 'int:y1', 'int:pixel'],
+@
+@ ['Triangle', 'GP_Context:in', 'int:x0', 'int:y0',
+@ 'int:x1', 'int:y1', 'int:x2', 'int:y2', 'int:pixel'],
+@ ['FillTriangle', 'GP_Context:in', 'int:x0', 'int:y0',
+@ 'int:x1', 'int:y1', 'int:x2', 'int:y2', 'int:pixel'],
+@
+@ ['Tetragon', 'GP_Context:in', 'int:x0', 'int:y0', 'int:x1', 'int:y1',
+@ 'int:x2', 'int:y2', 'int:x3', 'int:y3', 'int:pixel'],
+@ ['FillTetragon', 'GP_Context:in', 'int:x0', 'int:y0', 'int:x1', 'int:y1',
+@ 'int:x2', 'int:y2', 'int:x3', 'int:y3', 'int:pixel'],
+@ ]
+@
+@ def prep_context(id, pt):
+GP_Context *{{ id }} = GP_ContextAlloc(331, 331, GP_PIXEL_{{ pt.name }});
+@ end
+@
+@ def prep_int(id):
+int {{ id }} = 2;
+@ end
+@
+@ def prep_param(param, pt):
+@ if (param.split(':', 1)[0] == 'GP_Context'):
+{@ prep_context(param.split(':', 1)[1], pt) @}
+@ if (param.split(':', 1)[0] == 'float'):
+{@ prep_float(param.split(':', 1)[1]) @}
+@ if (param.split(':', 1)[0] == 'int'):
+{@ prep_int(param.split(':', 1)[1]) @}
+@ end
+@
+@ def get_param(param):
+@ if len(param.split(':', 1)) == 1:
+@ return 'NULL'
+@ else:
+@ return param.split(':', 1)[1]
+@ end
+@
+@ for fn in API_List:
+@ for pt in pixeltypes:
+@ if not pt.is_unknown():
static int Gfx_{{ fn[0]}}_{{ pt.name }}(void)
{
-%% for param in fn[1:]
-{{ prep_param(param, pt) }}
-%% endfor
+@ for param in fn[1:]:
+ {@ prep_param(param, pt) @}
+@ end
- GP_{{ fn[0] }}({{ get_param(fn[1]) }}{% for param in fn[2:] %}, {{ get_param(param) }}{% endfor %});
+ GP_{{ fn[0] }}({{ ', '.join(map(get_param, fn[1:])) }});
return TST_SUCCESS;
}
-%% endif
-%% endfor
-%% endfor
-
+@ end
+@
const struct tst_suite tst_suite = {
.suite_name = "Gfx API Coverage",
.tests = {
-%% for fn in API_List
-%% for pt in pixeltypes
-%% if not pt.is_unknown()
- {.name = "{{ fn[0] }} {{ pt.name }}",
+@ for fn in API_List:
+@ for pt in pixeltypes:
+@ if not pt.is_unknown():
+ {.name = "{{ fn[0] }} {{ pt.name }}",
.tst_fn = Gfx_{{ fn[0] }}_{{ pt.name }}},
-%% endif
-%% endfor
-%% endfor
+@ end
{.name = NULL}
}
};
-
-%% endblock body
diff --git a/tests/gfx/Makefile b/tests/gfx/Makefile
index c93bf99d..577b61e8 100644
--- a/tests/gfx/Makefile
+++ b/tests/gfx/Makefile
@@ -23,6 +23,6 @@ FillRect: common.o
include ../tests.mk
-include $(TOPDIR)/gen.mk
+include $(TOPDIR)/genn.mk
include $(TOPDIR)/app.mk
include $(TOPDIR)/post.mk
http://repo.or.cz/w/gfxprim.git/commit/1176d24e31d0d820628edf8b4d5ba74db4d5…
commit 1176d24e31d0d820628edf8b4d5ba74db4d51cb5
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Thu Oct 23 10:45:05 2014 +0200
Update .gitignore files.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/demos/bogoman/.gitignore b/demos/bogoman/.gitignore
new file mode 100644
index 00000000..8ba14a01
--- /dev/null
+++ b/demos/bogoman/.gitignore
@@ -0,0 +1 @@
+/bogoman
diff --git a/demos/c_simple/.gitignore b/demos/c_simple/.gitignore
index a9d725a0..62b24904 100644
--- a/demos/c_simple/.gitignore
+++ b/demos/c_simple/.gitignore
@@ -1,9 +1,35 @@
-backend_example
-filters_symmetry
-gfx_koch
-loaders
-loaders_example
-meta_data
-meta_data_dump
-tmp_file
-virtual_backend_example
+/SDL_glue
+/backend_example
+/backend_timers_example
+/blittest
+/convolution
+/data_storage
+/debug_handler
+/fileview
+/filters_symmetry
+/fonttest
+/gaussian_noise
+/gfx_koch
+/input_example
+/koch
+/linetest
+/loaders
+/loaders_example
+/loaders_register
+/memory_io
+/meta_data
+/pretty_print
+/randomshapetest
+/shapetest
+/showimage
+/sin_AA
+/textaligntest
+/timers
+/tmp_file
+/v4l2_grab
+/v4l2_show
+/version
+/virtual_backend_example
+/weighted_median
+/x11_windows
+/zip_container
diff --git a/tests/core/.gitignore b/tests/core/.gitignore
new file mode 100644
index 00000000..f52f0420
--- /dev/null
+++ b/tests/core/.gitignore
@@ -0,0 +1,10 @@
+/BlitClipped
+/BlitConv.gen
+/Context
+/Convert.gen
+/Convert_Scale.gen
+/Debug
+/GetPutPixel.gen
+/GetSetBits.gen
+/Pixel
+/WritePixel.gen
diff --git a/tests/filters/.gitignore b/tests/filters/.gitignore
new file mode 100644
index 00000000..608d042b
--- /dev/null
+++ b/tests/filters/.gitignore
@@ -0,0 +1,3 @@
+/APICoverage.gen
+/FilterMirrorH
+/FiltersCompare.gen
diff --git a/tests/framework/.gitignore b/tests/framework/.gitignore
new file mode 100644
index 00000000..ee4c9268
--- /dev/null
+++ b/tests/framework/.gitignore
@@ -0,0 +1 @@
+/test
diff --git a/tests/gfx/.gitignore b/tests/gfx/.gitignore
new file mode 100644
index 00000000..92632603
--- /dev/null
+++ b/tests/gfx/.gitignore
@@ -0,0 +1,15 @@
+/APICoverage.gen
+/Circle
+/CircleSeg
+/Ellipse
+/FillCircle
+/FillEllipse
+/FillRect
+/HLine
+/HLineAA
+/Line
+/LineAA
+/Polygon
+/PutPixelAA
+/VLine
+/gfx_benchmark
diff --git a/tests/input/.gitignore b/tests/input/.gitignore
new file mode 100644
index 00000000..c2490496
--- /dev/null
+++ b/tests/input/.gitignore
@@ -0,0 +1,2 @@
+/TimeStamp
+/Timer
diff --git a/tests/loaders/.gitignore b/tests/loaders/.gitignore
index 6b693da7..83ddae9d 100644
--- a/tests/loaders/.gitignore
+++ b/tests/loaders/.gitignore
@@ -1,15 +1,16 @@
-GIF
-IO
-PBM
-PGM
-PNG
-PNM
-PPM
-PCX
-JPG
-SaveAbort.gen
-SaveLoad.gen
-ZIP
-loaders_suite
-Loader
-DataStorage
+/DataStorage
+/Exif
+/GIF
+/IO
+/JPG
+/Loader
+/PBM
+/PCX
+/PGM
+/PNG
+/PNM
+/PPM
+/SaveAbort.gen
+/SaveLoad.gen
+/ZIP
+/loaders_suite
http://repo.or.cz/w/gfxprim.git/commit/c962710c01d67f93a2a39d49db5b5a678df8…
commit c962710c01d67f93a2a39d49db5b5a678df8070e
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Thu Oct 23 10:31:19 2014 +0200
JP2: Fix loader gettting stuck on no end marker.
In case that the file ended up prematurely the read callback will spin
in infinite loop because the read has returned zero. Change it to return
-1 in this case which causes the openjpeg loader abort instead of the
infinite loop.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/libs/loaders/GP_JP2.c b/libs/loaders/GP_JP2.c
index 39b080d2..e1694ff2 100644
--- a/libs/loaders/GP_JP2.c
+++ b/libs/loaders/GP_JP2.c
@@ -86,7 +86,13 @@ static const char *color_space_name(OPJ_COLOR_SPACE color_space)
static OPJ_SIZE_T jp2_io_read(void *buf, OPJ_SIZE_T size, void *io)
{
- return GP_IORead(io, buf, size);
+ ssize_t ret;
+ ret = GP_IORead(io, buf, size);
+
+ if (ret == 0)
+ return -1;
+
+ return ret;
}
static void fill_metadata(opj_image_t *img, GP_DataStorage *storage)
http://repo.or.cz/w/gfxprim.git/commit/c0cfb2f6ac22689db526b97aa65cb0ca89bb…
commit c0cfb2f6ac22689db526b97aa65cb0ca89bbb1cf
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Jul 21 22:09:24 2014 +0200
loaders: Rewrite Exif loader and meta data storage
Now all loader functions have Ex variant that has data storage parameter
to store image metadata to.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/build/syms/Loaders_symbols.txt b/build/syms/Loaders_symbols.txt
index 24d0e037..5ef70802 100644
--- a/build/syms/Loaders_symbols.txt
+++ b/build/syms/Loaders_symbols.txt
@@ -1,18 +1,18 @@
GP_MatchJPG
GP_ReadJPG
+GP_ReadJPGEx
GP_LoadJPG
+GP_LoadJPGEx
GP_WriteJPG
GP_SaveJPG
-GP_ReadJPGMetaData
-GP_LoadJPGMetaData
GP_JPG
GP_MatchPNG
GP_ReadPNG
+GP_ReadPNGEx
GP_LoadPNG
-GP_ReadPNGMetaData
-GP_LoadPNGMetaData
+GP_LoadPNGEx
GP_WritePNG
GP_SavePNG
GP_PNG
@@ -20,6 +20,7 @@ GP_PNG
GP_MatchBMP
GP_WriteBMP
GP_LoadBMP
+GP_ReadBMPEx
GP_ReadBMP
GP_SaveBMP
GP_BMP
@@ -27,21 +28,27 @@ GP_BMP
GP_MatchPSP
GP_ReadPSP
GP_LoadPSP
+GP_ReadPSPEx
GP_PSP
GP_MatchGIF
-GP_LoadGIF
GP_ReadGIF
+GP_ReadGIFEx
+GP_LoadGIF
+GP_LoadGIFEx
GP_GIF
-GP_MatchTIFF
GP_ReadTIFF
GP_LoadTIFF
+GP_ReadTIFFEx
+GP_LoadTIFFEx
+GP_MatchTIFF
GP_WriteTIFF
GP_SaveTIFF
GP_TIFF
GP_ReadPBM
+GP_ReadPBMEx
GP_LoadPBM
GP_WritePBM
GP_SavePBM
@@ -49,6 +56,7 @@ GP_MatchPBM
GP_PBM
GP_ReadPGM
+GP_ReadPGMEx
GP_LoadPGM
GP_WritePGM
GP_SavePGM
@@ -56,6 +64,7 @@ GP_MatchPGM
GP_PGM
GP_ReadPPM
+GP_ReadPPMEx
GP_LoadPPM
GP_WritePPM
GP_SavePPM
@@ -63,6 +72,7 @@ GP_MatchPPM
GP_PPM
GP_ReadPNM
+GP_ReadPNMEx
GP_LoadPNM
GP_WritePNM
GP_SavePNM
@@ -71,48 +81,44 @@ GP_PNM
GP_ReadJP2
GP_LoadJP2
+GP_ReadJP2Ex
+GP_LoadJP2Ex
GP_MatchJP2
GP_JP2
GP_ReadPCX
GP_LoadPCX
+GP_ReadPCXEx
+GP_LoadPCXEx
GP_MatchPCX
GP_PCX
GP_ReadPSD
+GP_ReadPSDEx
GP_LoadPSD
GP_MatchPSD
GP_PSD
+GP_ReadExif
+
GP_SaveTmpFile
GP_LoadTmpFile
GP_LoaderBySignature
GP_LoaderByFilename
GP_LoaderLoadImage
+GP_LoaderLoadImageEx
+GP_LoaderReadImage
+GP_LoaderReadImageEx
GP_LoaderSaveImage
GP_ReadImage
GP_LoadImage
-GP_SaveImage
GP_LoadMetaData
+GP_SaveImage
GP_ListLoaders
GP_LoaderRegister
GP_LoaderUnregister
-GP_MetaDataGetString
-GP_MetaDataCreateRat
-GP_MetaDataCreateInt
-GP_MetaDataCreateRecord
-GP_MetaDataGetInt
-GP_MetaDataDestroy
-GP_MetaDataClear
-GP_MetaDataCreateDouble
-GP_MetaDataCreateString
-GP_MetaDataCreate
-GP_MetaDataPrint
-GP_MetaDataGetDouble
-GP_MetaDataFromExif
-
GP_ContainerLoad
GP_ContainerSeek
@@ -138,3 +144,17 @@ GP_IOPrintF
GP_IOZlib
GP_IOZlibReset
+
+GP_DataStorageCreate
+GP_DataStorageDestroy
+GP_DataStorageClear
+GP_DataStorageRoot
+GP_DataStorageGet
+GP_DataStorageAdd
+GP_DataStorageAddInt
+GP_DataStorageAddDouble
+GP_DataStorageAddString
+GP_DataStorageAddRational
+GP_DataStorageAddDict
+GP_DataTypeName
+GP_DataPrint
diff --git a/demos/c_simple/Makefile b/demos/c_simple/Makefile
index 0abe0214..654df984 100644
--- a/demos/c_simple/Makefile
+++ b/demos/c_simple/Makefile
@@ -13,12 +13,12 @@ INCLUDE=
LDLIBS+=-lrt
APPS=backend_example loaders_example loaders filters_symmetry gfx_koch- virtual_backend_example meta_data meta_data_dump tmp_file showimage+ virtual_backend_example meta_data tmp_file showimage v4l2_show v4l2_grab convolution weighted_median shapetest koch input_example fileview linetest randomshapetest fonttest loaders_register blittest textaligntest sin_AA x11_windows debug_handler gaussian_noise version pretty_print timers- zip_container backend_timers_example memory_io
+ zip_container backend_timers_example memory_io data_storage
ifeq ($(HAVE_LIBSDL),yes)
APPS+=SDL_glue
@@ -36,7 +36,6 @@ tmp_file: LDLIBS+=-lgfxprim-loaders
filters_symmetry: LDLIBS+=-lgfxprim-loaders
gfx_koch: LDLIBS+=-lgfxprim-loaders -lm
meta_data: LDLIBS+=-lgfxprim-loaders
-meta_data_dump: LDLIBS+=-lgfxprim-loaders
v4l2_show: LDLIBS+=-lgfxprim-grabbers -lgfxprim-backends
v4l2_grab: LDLIBS+=-lgfxprim-grabbers -lgfxprim-loaders
convolution: LDLIBS+=-lgfxprim-loaders
@@ -56,6 +55,7 @@ sin_AA: LDLIBS+=-lgfxprim-backends -lm
x11_windows: LDLIBS+=-lgfxprim-backends
zip_container: LDLIBS+=-lgfxprim-loaders -lgfxprim-backends
memory_io: LDLIBS+=-lgfxprim-backends -lgfxprim-loaders
+data_storage: LDLIBS+=-lgfxprim-loaders
include $(TOPDIR)/app.mk
include $(TOPDIR)/post.mk
diff --git a/demos/c_simple/meta_data_dump.c b/demos/c_simple/data_storage.c
similarity index 60%
copy from demos/c_simple/meta_data_dump.c
copy to demos/c_simple/data_storage.c
index 8fc25263..902bbdbb 100644
--- a/demos/c_simple/meta_data_dump.c
+++ b/demos/c_simple/data_storage.c
@@ -16,52 +16,60 @@
* 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> *
* *
*****************************************************************************/
/*
- Read image meta-data and print them into stdout.
+ Data storage operations example.
*/
#include <stdio.h>
-#include <string.h>
-#include <errno.h>
#include <GP.h>
-#define SEP -"-----------------------------------------------------------------------------"
-
-int main(int argc, char *argv[])
+int main(void)
{
- GP_MetaData *data = GP_MetaDataCreate(80);
- int i;
+ GP_DataStorage *storage = GP_DataStorageCreate();
+ GP_DataNode *flags;
- if (argc < 2) {
- fprintf(stderr, "Takes an image(s) as parameter(s)n");
+ if (storage == NULL)
return 1;
- }
- //GP_SetDebugLevel(10);
+ printf("Empty storage -----------------------n");
+ GP_DataPrint(GP_DataStorageRoot(storage));
+ printf("-------------------------------------nn");
+
+ GP_DataNode data = {
+ .type = GP_DATA_INT,
+ .value.i = 300,
+ .id = "dpi"
+ };
+
+ GP_DataStorageAdd(storage, NULL, &data);
+
+ GP_DataStorageAddString(storage, NULL, "orientation", "top-down");
+
+ printf("Flat storage ------------------------n");
+ GP_DataPrint(GP_DataStorageRoot(storage));
+ printf("-------------------------------------nn");
+
+ flags = GP_DataStorageAddDict(storage, NULL, "flags");
- for (i = 1; i < argc; i++) {
- puts(SEP);
- printf("Opening '%s'n", argv[i]);
+ data.type = GP_DATA_INT;
+ data.id = "compression_level";
+ data.value.i = 10;
- GP_MetaDataClear(data);
+ GP_DataStorageAdd(storage, flags, &data);
- if (GP_LoadMetaData(argv[i], data)) {
- fprintf(stderr, "Failed to read '%s' meta-data: %sn",
- argv[1], strerror(errno));
- } else {
- GP_MetaDataPrint(data);
- }
- }
+ printf("Recursive storage -------------------n");
+ GP_DataPrint(GP_DataStorageRoot(storage));
+ printf("-------------------------------------nn");
- puts(SEP);
+ GP_DataPrint(GP_DataStorageGet(storage, NULL, "dpi"));
+ GP_DataStorageDestroy(storage);
return 0;
}
diff --git a/demos/c_simple/meta_data.c b/demos/c_simple/meta_data.c
index a2c9a645..2e217818 100644
--- a/demos/c_simple/meta_data.c
+++ b/demos/c_simple/meta_data.c
@@ -16,69 +16,57 @@
* 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> *
* *
*****************************************************************************/
/*
- Meta-data storage operations example.
-
- Meta-data storage is used to store image meta-data (if present) such as
- physical size, creation date, etc...
-
- Meta-data storage is basically an typed dictionary.
-
- This example shows low-level interface to GP_MetaData structure.
+ Read image meta-data and print them into stdout.
*/
#include <stdio.h>
+#include <string.h>
+#include <errno.h>
#include <GP.h>
-int main(void)
-{
- GP_MetaData *data = GP_MetaDataCreate(10);
+#define SEP +"-----------------------------------------------------------------------------"
- //GP_SetDebugLevel(10);
+int main(int argc, char *argv[])
+{
+ GP_DataStorage *storage;
+ int i;
- if (data == NULL)
+ if (argc < 2) {
+ fprintf(stderr, "Takes an image(s) as parameter(s)n");
return 1;
+ }
- /*
- * Create integer
- *
- * May fail, if there is allready record with id 'dpi' or
- * if there is no space left.
- */
- GP_MetaDataCreateInt(data, "dpi", 300);
-
- /*
- * Create an string.
- *
- * The last parameter says, if the string should be duplicated
- * in the metadata storage.
- */
- GP_MetaDataCreateString(data, "author", "Foo Bar <foo(a)bar.net>", 0, 1);
- GP_MetaDataCreateString(data, "comment", "Created in hurry.", 0, 1);
- GP_MetaDataCreateDouble(data, "pi", 3.141592);
+ storage = GP_DataStorageCreate();
- const char *ret;
+ if (!storage) {
+ fprintf(stderr, "Failed to create data storagen");
+ return 1;
+ }
- ret = GP_MetaDataGetString(data, "comment");
+ for (i = 1; i < argc; i++) {
+ puts(SEP);
+ printf("Opening '%s'n", argv[i]);
- if (ret != NULL)
- printf("Found string 'comment' = '%s'n", ret);
- else
- printf("ERROR: cannot cound string 'comment'n");
+ GP_DataStorageClear(storage);
- printf("n");
+ if (GP_LoadMetaData(argv[i], storage)) {
+ fprintf(stderr, "Failed to read '%s' meta-data: %sn",
+ argv[i], strerror(errno));
+ } else {
+ GP_DataStoragePrint(storage);
+ }
+ }
- /*
- * Print all meta-data
- */
- GP_MetaDataPrint(data);
+ puts(SEP);
return 0;
}
diff --git a/include/loaders/GP_BMP.h b/include/loaders/GP_BMP.h
index 982de158..da388d0b 100644
--- a/include/loaders/GP_BMP.h
+++ b/include/loaders/GP_BMP.h
@@ -25,14 +25,18 @@
#include "loaders/GP_Loader.h"
...e-mail trimmed, has been too large.
1
0
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