and new much cleaner tree.

SVN revision: 12113
This commit is contained in:
Carsten Haitzler 2004-11-01 09:45:31 +00:00
parent 31660022d0
commit 5886f2a7cd
156 changed files with 50041 additions and 0 deletions

30
AUTHORS Normal file
View File

@ -0,0 +1,30 @@
The Rasterman (Carsten Haitzler) <raster@rasterman.com> <raster@valinux.com>
Ryan Gustafson <ryan_gustafson@yahoo.com>
Mandrake (Geoff Harrison) <mandrake@mandrake.net>
Willem Monsuwe <willem@stack.nl>
KainX (Michael Jennings) <mej@eterm.org>
Eric Dorland <dorland@lords.com>
Chutt (Isaac Richards) <ijr@po.cwru.edu>
giblet (Tom Gilbert) <tom@linuxbrit.co.uk>
Takis <takis@lumumba.luc.ac.be>
Dan Maas <dmaas@dcine.com>
Platon Fomichev <pla@cland.ru>
boris (Chris Ross) <chris@darkrock.co.uk>
Martin Grimm <grimm.martin@gmx.de>
Matt McClanahan <cardinal@dodds.net>
Steve Langasek <vorlon@dodds.net>
Christophe Tronche <ch.tronche@computer.org>
Nathan Ingersoll <ningerso@d.umn.edu>
Masa(Masahiko) Mori <masa@engr.sgi.com>
Term (Lyle Kempler) <term@twistedpath.org>
Adam Kisiel <kisiel@if.pw.edu.pl>
Carsten Pfeiffer <carpdjih@sp.zrz.tu-berlin.de>
Lightman (Franz Marini) <marini@pcmenelao.mi.infn.it>
Mark Bainter <mark-e@cymry.org>
Brian Lindholm <brian_lindholm@users.sourceforge.net>
Renchi Raju <renchi@pooh.tam.uiuc.edu>
Yuri Hudobin <glassy_ape@users.sourceforge.net>
Radoslaw Grzanka <radekg2@poczta.onet.pl>
Kim Woelders <kim@woelders.dk>
Nick Blievers <nickb@sgi.com>
Mike Castle <dalgoda@ix.netcom.com>

28
COPYING Normal file
View File

@ -0,0 +1,28 @@
Copyright (C) 2000 Carsten Haitzler and various contributors (see AUTHORS)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies of the Software and its Copyright notices. In addition publicly
documented acknowledgment must be given that this software has been used if no
source code of this software is made available publicly. This includes
acknowledgments in either Copyright notices, Manuals, Publicity and Marketing
documents or any documentation provided with any product containing this
software. This License does not apply to any software that links to the
libraries provided by this software (statically or dynamically), but only to
the software provided.
Please see the COPYING.PLAIN for a plain-english explanation of this notice
and it's intent.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

33
COPYING-PLAIN Normal file
View File

@ -0,0 +1,33 @@
Plain English Copyright Notice
This file is not intended to be the actual License. The reason this file
exists is that we here are programmers and engineers. We aren't lawyers. We
provide licenses that we THINK say the right things, but we have our own
intentions at heart. This is a plain-english explanation of what those
intentions are, and if you follow them you will be within the "spirit" of
the license.
The intent is for us to enjoy writing software that is useful to us (the
AUTHORS) and allow others to use it freely and also benefit from the work we
put into making it. We don't want to restrict others using it. They should
not *HAVE* to make the source code of the applications they write that
simply link to these libraries (be that statically or dynamically), or for
them to be limited as to what license they choose to use (be it open, closed
or anything else). But we would like to know you are using these libraries.
We simply would like to know that it has been useful to someone. This is why
we ask for acknowledgement of some sort.
You can do what you want with the source of this software - it doesn't
matter. We still have it here for ourselves and it is open and free to use
and download and play with. It can't be taken away. We don't really mind what
you do with the source to your software. We would simply like to know that
you are using it - especially if it makes it to a commerical product. If you
simply e-mail all the AUTHORS (see COPYING and AUTHORS files) telling us, and
then make sure you include a paragraph or page in the manual for the product
with the copyright notice and state that you used this software, we will be
very happy. If you want to contribute back modifications and fixes you may have
made we will welcome those too with open arms (generally). If you want help
with changes needed, ports needed or features to be added, arrangements can
be easily made with some dialogue.
Carsten Haitzler <raster@rasterman.com>

3007
ChangeLog Normal file

File diff suppressed because it is too large Load Diff

139
Doxyfile Normal file
View File

@ -0,0 +1,139 @@
PROJECT_NAME = Imlib2
PROJECT_NUMBER =
OUTPUT_DIRECTORY = doc
INPUT = imlib2.c
IMAGE_PATH = doc/img
OUTPUT_LANGUAGE = English
GENERATE_HTML = YES
HTML_OUTPUT = html
HTML_FILE_EXTENSION = .html
HTML_HEADER = doc/head.html
HTML_FOOTER = doc/foot.html
HTML_STYLESHEET = doc/imlib2.css
HTML_ALIGN_MEMBERS = YES
ENUM_VALUES_PER_LINE = 1
GENERATE_HTMLHELP = NO
CHM_FILE =
HHC_LOCATION =
GENERATE_CHI = NO
BINARY_TOC = NO
TOC_EXPAND = NO
DISABLE_INDEX = NO
EXTRACT_ALL = NO
EXTRACT_PRIVATE = NO
EXTRACT_STATIC = NO
EXTRACT_LOCAL_CLASSES = NO
HIDE_UNDOC_MEMBERS = YES
HIDE_UNDOC_CLASSES = YES
HIDE_FRIEND_COMPOUNDS = YES
BRIEF_MEMBER_DESC = YES
REPEAT_BRIEF = YES
ALWAYS_DETAILED_SEC = NO
INLINE_INHERITED_MEMB = NO
FULL_PATH_NAMES = NO
STRIP_FROM_PATH =
INTERNAL_DOCS = NO
STRIP_CODE_COMMENTS = YES
CASE_SENSE_NAMES = YES
SHORT_NAMES = NO
HIDE_SCOPE_NAMES = NO
VERBATIM_HEADERS = NO
SHOW_INCLUDE_FILES = NO
JAVADOC_AUTOBRIEF = YES
MULTILINE_CPP_IS_BRIEF = NO
DETAILS_AT_TOP = NO
INHERIT_DOCS = YES
INLINE_INFO = YES
SORT_MEMBER_DOCS = YES
DISTRIBUTE_GROUP_DOC = NO
TAB_SIZE = 2
GENERATE_TODOLIST = YES
GENERATE_TESTLIST = YES
GENERATE_BUGLIST = YES
GENERATE_DEPRECATEDLIST= YES
ALIASES =
ENABLED_SECTIONS =
MAX_INITIALIZER_LINES = 30
OPTIMIZE_OUTPUT_FOR_C = YES
OPTIMIZE_OUTPUT_JAVA = NO
SHOW_USED_FILES = NO
QUIET = NO
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_FORMAT = "$file:$line: $text"
WARN_LOGFILE =
FILE_PATTERNS =
RECURSIVE = NO
EXCLUDE =
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS =
EXAMPLE_PATH =
EXAMPLE_PATTERNS =
EXAMPLE_RECURSIVE = NO
INPUT_FILTER =
FILTER_SOURCE_FILES = NO
SOURCE_BROWSER = NO
INLINE_SOURCES = NO
REFERENCED_BY_RELATION = YES
REFERENCES_RELATION = YES
ALPHABETICAL_INDEX = YES
COLS_IN_ALPHA_INDEX = 2
IGNORE_PREFIX =
GENERATE_TREEVIEW = NO
TREEVIEW_WIDTH = 250
GENERATE_LATEX = YES
LATEX_OUTPUT = latex
LATEX_CMD_NAME = latex
MAKEINDEX_CMD_NAME = makeindex
COMPACT_LATEX = NO
PAPER_TYPE = a4wide
EXTRA_PACKAGES =
LATEX_HEADER =
PDF_HYPERLINKS = YES
USE_PDFLATEX = NO
LATEX_BATCHMODE = NO
GENERATE_RTF = NO
RTF_OUTPUT = rtf
COMPACT_RTF = NO
RTF_HYPERLINKS = NO
RTF_STYLESHEET_FILE =
RTF_EXTENSIONS_FILE =
GENERATE_MAN = YES
MAN_OUTPUT = man
MAN_EXTENSION = .3
MAN_LINKS = YES
GENERATE_XML = YES
XML_SCHEMA =
XML_DTD =
GENERATE_AUTOGEN_DEF = NO
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = NO
EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = NO
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED =
EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = YES
TAGFILES =
GENERATE_TAGFILE =
ALLEXTERNALS = NO
EXTERNAL_GROUPS = YES
PERL_PATH = /usr/bin/perl
CLASS_DIAGRAMS = NO
HIDE_UNDOC_RELATIONS = YES
HAVE_DOT = NO
CLASS_GRAPH = NO
COLLABORATION_GRAPH = NO
TEMPLATE_RELATIONS = NO
INCLUDE_GRAPH = NO
INCLUDED_BY_GRAPH = NO
GRAPHICAL_HIERARCHY = NO
DOT_IMAGE_FORMAT = png
DOT_PATH =
DOTFILE_DIRS =
MAX_DOT_GRAPH_WIDTH = 512
MAX_DOT_GRAPH_HEIGHT = 512
GENERATE_LEGEND = YES
DOT_CLEANUP = YES
SEARCHENGINE = NO

14
INSTALL Normal file
View File

@ -0,0 +1,14 @@
COMPILING and INSTALLING:
If you got a official release tar archive do:
./configure
( otherwise if you got this from enlightenment cvs do: ./autogen.sh )
Then to compile:
make
To install (run this as root, or the user who handles installs):
make install
NOTE: You MUST make install Epeg for it to run properly.

22
Makefile.am Normal file
View File

@ -0,0 +1,22 @@
## Process this file with automake to produce Makefile.in
SUBDIRS = src data doc debian
MAINTAINERCLEANFILES = Makefile.in aclocal.m4 config.guess \
config.h.in config.sub configure install-sh \
ltconfig ltmain.sh missing mkinstalldirs \
stamp-h.in imlib2_docs.tar imlib2_docs.tar.gz imlib2.c
dist-hook:
./gendoc; \
tar cvf imlib2_docs.tar doc; \
rm -f imlib2_docs.tar.gz; \
gzip -9 imlib2_docs.tar;
bin_SCRIPTS = imlib2-config
EXTRA_DIST = README AUTHORS COPYING COPYING-PLAIN TODO imlib2.spec imlib2.c.in imlib2.pc.in gendoc Doxyfile imlib2_docs.tar.gz
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = imlib2.pc

0
NEWS Normal file
View File

41
README Normal file
View File

@ -0,0 +1,41 @@
###############################################################################
# #
# I M L I B 2 #
# #
###############################################################################
This is the Imlib 2 library - a library that does image file loading and
saving as well as rendering, manipulation, arbitrary polygon support, etc.
It does ALL of these operations FAST. Imlib2 also tries to be highly
intelligent about doing them, so writing naive programs can be done
easily, without sacrificing speed.
This is a complete rewrite over the Imlib 1.x series. The architecture is
more modular, simple, and flexible. See index.html in the doc/ directory
for more information.
Imlib2 requires several libraries to be already installed. These are:
libjpeg http://www.ijg.org/
libpng http://www.libpng.org/pub/png/libpng.html
freetype 2.1.x http://www.freetype.org/
For examples of this library in use, seek:
Eterm http://www.eterm.org/ (CVS version only, currently)
feh http://www.linuxbrit.co.uk/feh.html
geist http://www.linuxbrit.co.uk/geist.html
A blurb about each of the directories:
debian/ Debian build files
demo/ Demo view program
doc/ Documentation for imlib2, primarily in html
filters/ Filter shared objects
libltdl/ Libtool LGPL-licensed loadable module support library source
loaders/ Imlib2's image loader-savers (jpg, png, etc)
src/ Imlib2 main source
test/ Test program(s)

6
TODO Normal file
View File

@ -0,0 +1,6 @@
* line code doesnt draw nice liens when clipping - fix
* filled polygons can break fill bounds on corner cases - fix
* go thru TODOs and FIXMEs
evas2 has fixed code for these 2 in it that work just fine. just need to
port over (should be fairly easy).

13
autogen.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
rm -rf autom4te.cache
rm -f aclocal.m4
echo "Running aclocal..."; aclocal $ACLOCAL_FLAGS -I m4 \
&& echo "Running autoheader..."; autoheader \
&& echo "Running autoconf..."; autoconf \
&& echo "Running libtoolize..."; (libtoolize --automake || glibtoolize --automake) \
&& echo "Running automake..."; automake --add-missing --copy --gnu
### If you want this, uncomment it.
./configure "$@"

394
configure.in Normal file
View File

@ -0,0 +1,394 @@
# get rid of that stupid cache mechanism
rm -f config.cache
AC_INIT(configure.in)
AC_CANONICAL_BUILD
AC_CANONICAL_HOST
AC_CANONICAL_TARGET
AC_ISC_POSIX
AM_INIT_AUTOMAKE(imlib2, 1.2.0)
AM_CONFIG_HEADER(config.h)
AC_C_BIGENDIAN
AC_PROG_CC
AM_PROG_CC_STDC
AC_HEADER_STDC
AC_C_CONST
AM_ENABLE_SHARED
AM_PROG_LIBTOOL
if test "x${exec_prefix}" = "xNONE"; then
if test "x${prefix}" = "xNONE"; then
bindir="${ac_default_prefix}/bin";
else
bindir="${prefix}/bin";
fi
else
if test "x${prefix}" = "xNONE"; then
bindir="${ac_default_prefix}/bin";
else
bindir="${prefix}/bin";
fi
fi
if test "x${exec_prefix}" = "xNONE"; then
if test "x${prefix}" = "xNONE"; then
libdir="${ac_default_prefix}/lib";
else
libdir="${prefix}/lib";
fi
else
if test "x${prefix}" = "xNONE"; then
libdir="${ac_default_prefix}/lib";
else
libdir="${prefix}/lib";
fi
fi
dnl Set PACKAGE_BIN_DIR in config.h.
if test "x${bindir}" = 'xNONE'; then
if test "x${prefix}" = "xNONE"; then
AC_DEFINE_UNQUOTED(PACKAGE_BIN_DIR, "${ac_default_prefix}/bin", [Installation directory for user executables])
else
AC_DEFINE_UNQUOTED(PACKAGE_BIN_DIR, "${prefix}/bin", [Installation directory for user executables])
fi
else
AC_DEFINE_UNQUOTED(PACKAGE_BIN_DIR, "${bindir}", [Installation directory for user executables])
fi
dnl Set PACKAGE_LIB_DIR in config.h.
if test "x${libdir}" = 'xNONE'; then
if test "x${prefix}" = "xNONE"; then
AC_DEFINE_UNQUOTED(PACKAGE_LIB_DIR, "${ac_default_prefix}/lib", [Installation directory for libraries])
else
AC_DEFINE_UNQUOTED(PACKAGE_LIB_DIR, "${prefix}/lib", [Installation directory for libraries])
fi
else
AC_DEFINE_UNQUOTED(PACKAGE_LIB_DIR, "${libdir}", [Installation directory for libraries])
fi
dnl Set PACKAGE_DATA_DIR in config.h.
if test "x${datadir}" = 'x${prefix}/share'; then
if test "x${prefix}" = "xNONE"; then
AC_DEFINE_UNQUOTED(PACKAGE_DATA_DIR, "${ac_default_prefix}/share/${PACKAGE}", "Package installed data destination")
else
AC_DEFINE_UNQUOTED(PACKAGE_DATA_DIR, "${prefix}/share/${PACKAGE}", "Package installed data destination")
fi
else
AC_DEFINE_UNQUOTED(PACKAGE_DATA_DIR, "${datadir}/${PACKAGE}", "Package installed data destination")
fi
dnl Set PACKAGE_SOURCE_DIR in config.h.
packagesrcdir=`cd $srcdir && pwd`
AC_DEFINE_UNQUOTED(PACKAGE_SOURCE_DIR, "${packagesrcdir}", [Source code directory])
mmx=no
AC_ARG_ENABLE(mmx,[ --disable-mmx attempt compiling using mmx assembly [default=yes]],
[
if test x$enableval = xyes; then
mmx=yes
AC_MSG_RESULT(enabling mmx support)
else
mmx=no
AC_MSG_RESULT(disabling mmx support)
fi
],
[
if test x$target_os = xlinux-gnu; then
if test x$target_cpu = x$host_cpu; then
mmx=`cat /proc/cpuinfo | grep mmx`
if test -n "$mmx"; then
mmx=yes
fi
else
echo ""
echo "You are cross-compiling on a "$host_cpu" machine for a "$target_os" machine."
echo "If this target supports mmx, please enable mmx with --enable-mmx as a"
echo "configure option."
echo ""
fi
else
echo ""
echo "You are not running Linux - This script cannot auto-detect mmx assembly."
echo "You will have to enable the mmx assembly (which gives anywhere from 10%"
echo "to 300% speedups) by adding --enable-mmx on the configure command-line."
echo ""
fi
]
)
if test x$mmx = xyes; then
AC_DEFINE(DO_MMX_ASM, 1, [enabling MMX Assembly])
AC_MSG_RESULT(enabled mmx support)
else
AC_MSG_RESULT(disabled mmx support)
fi
AM_CONDITIONAL(BUILD_MMX, test x$mmx = xyes)
ASFLAGS="$ASFLAGS -I../"
AS=$CC
AC_SUBST(ASFLAGS)
AC_SUBST(AS)
CCASFLAGS="$ASFLAGS"
CCAS="$AS"
AC_SUBST(CCASFLAGS)
AC_SUBST(CCAS)
# check for freetype
AC_ARG_WITH(freetype-config,
[ --with-freetype-config=FREETYPE_CONFIG use freetype-config specified ],
[
PROG_CONFIG=$withval;
echo "using "$PROG_CONFIG" for freetype-config";
],[
PROG="freetype-config";
AC_PATH_PROG(PROG_CONFIG, $PROG, "", $PATH)
])
if test -n "$FREETYPE_CONFIG"; then
PROG_CONFIG=$FREETYPE_CONFIG;
fi
if test -z "$PROG_CONFIG"; then
echo $PROG " is not in your \$PATH. Please ensure it is.";
echo "You may need to install the library and/or development packages";
echo "that contain this configure-script.";
echo "FATAL ERROR. ABORT.";
exit -1;
fi
freetype_cflags=`$PROG_CONFIG --cflags`
freetype_libs=`$PROG_CONFIG --libs`
x11=no
AC_ARG_ENABLE(x11,[ --disable-x11 attempt to build with X11 support [default=yes]],
[
if test x$enableval = xyes; then
have_x=yes
else
have_x=no
fi
],
[
AC_CHECK_HEADER(X11/X.h,
[ have_x="yes" ],
[ have_x="no" ]
)
]
)
AC_MSG_CHECKING(whether X11 support is to be enabled)
if test "x$have_x" = "xyes"; then
x_dir="/usr/X11R6";
x_cflags="-I"$x_dir"/include"
x_libs="-L"$x_dir"/lib -lX11 -lXext"
AC_MSG_RESULT(enabling X11 support)
AM_CONDITIONAL(BUILD_X11, true)
AC_DEFINE(BUILD_X11, 1, [enabling X11 support])
else
x_dir=""
x_cflags=""
x_libs=""
AC_MSG_RESULT(disabling X11 support)
AM_CONDITIONAL(BUILD_X11, false)
fi
dlopen_libs=""
AC_CHECK_LIB(dl, dlopen, dlopen_libs=-ldl)
my_includes=$freetype_cflags" "$x_cflags" "
my_libs=$freetype_libs" "$x_libs" "$dlopen_libs" -lm"
AC_SUBST(my_includes)
AC_SUBST(my_libs)
AC_CHECK_LIB(jpeg, jpeg_destroy_decompress,
jpeg_ok=yes,
jpeg_ok=no
AC_MSG_WARN(*** Native JPEG support will not be built (JPEG library not found) ***),
)
if test "$jpeg_ok" = yes; then
AC_MSG_CHECKING([for jpeglib.h])
AC_TRY_CPP(
[#include <stdio.h>
#undef PACKAGE
#undef VERSION
#include <jpeglib.h>],
jpeg_ok=yes,
jpeg_ok=no)
AC_MSG_RESULT($jpeg_ok)
if test "$jpeg_ok" = yes; then
JPEGLIBS="-ljpeg"
else
AC_MSG_WARN(*** Native JPEG support will not be built (JPEG header file not found) ***)
fi
fi
AM_CONDITIONAL(BUILD_JPEG_LOADER, test "$jpeg_ok" = yes)
AC_SUBST(JPEGLIBS)
AC_CHECK_LIB(png, png_read_info,
png_ok=yes,
png_ok=no
AC_MSG_WARN(*** Native PNG support will not be built (PNG library not found) ***),
-lz -lm)
if test "$png_ok" = yes; then
AC_MSG_CHECKING([for png.h])
AC_TRY_CPP(
[#include <stdio.h>
#undef PACKAGE
#undef VERSION
#include <png.h>],
png_ok=yes,
png_ok=no)
AC_MSG_RESULT($png_ok)
if test "$png_ok" = yes; then
PNGLIBS="-lpng -lz -lm"
else
AC_MSG_WARN(*** Native PNG support will not be built (PNG header file not found) ***)
fi
fi
AM_CONDITIONAL(BUILD_PNG_LOADER, test "$png_ok" = yes)
AC_SUBST(PNGLIBS)
AC_CHECK_LIB(tiff, TIFFReadScanline,
tiff_libs="-ltiff"
tiff_ok=yes,
AC_CHECK_LIB(tiff, TIFFReadScanline,
tiff_libs="-ltiff -ljpeg -lz -lm"
tiff_ok=yes,
AC_CHECK_LIB(tiff34, TIFFReadScanline,
tiff_libs="-ltiff34 -ljpeg -lz -lm"
tiff_ok=yes,
tiff_ok=no
AC_MSG_WARN(*** Native TIFF support will not be built (TIFF library not found) ***),
-ljpeg -lz -lm),
-ljpeg -lz -lm),
)
if test "$tiff_ok" = yes; then
AC_MSG_CHECKING([for tiffio.h])
AC_TRY_CPP(
[#include <stdio.h>
#undef PACKAGE
#undef VERSION
#include <tiffio.h>],
tiff_ok=yes,
tiff_ok=no)
AC_MSG_RESULT($tiff_ok)
if test "$tiff_ok" = yes; then
TIFFLIBS=$tiff_libs
else
AC_MSG_WARN(*** Native TIFF support will not be built (TIFF header file not found) ***)
fi
fi
AM_CONDITIONAL(BUILD_TIFF_LOADER, test "$tiff_ok" = yes)
AC_SUBST(TIFFLIBS)
AC_CHECK_LIB(ungif, DGifOpenFileName,
gif_libs="-lungif"
gif_ok=yes,
gif_ok=no,
)
if test "$gif_ok" = yes; then
AC_MSG_CHECKING([for gif_lib.h])
AC_TRY_CPP(
[#include <stdio.h>
#undef PACKAGE
#undef VERSION
#include <gif_lib.h>],
gif_ok=yes,
gif_ok=no)
AC_MSG_RESULT($gif_ok)
if test "$gif_ok" = yes; then
GIFLIBS=$gif_libs
fi
fi
if test "$gif_ok" = no; then
AC_CHECK_LIB(gif, DGifOpenFileName,
gif_libs="-lgif"
gif_ok=yes,
gif_ok=no
AC_MSG_WARN(*** Native GIF support will not be built (GIF library not found) ***),
)
if test "$gif_ok" = yes; then
AC_MSG_CHECKING([for gif_lib.h])
AC_TRY_CPP(
[#include <stdio.h>
#undef PACKAGE
#undef VERSION
#include <gif_lib.h>],
gif_ok=yes,
gif_ok=no)
AC_MSG_RESULT($gif_ok)
if test "$gif_ok" = yes; then
GIFLIBS=$gif_libs
else
AC_MSG_WARN(*** Native GIF support will not be built (GIF header file not found) ***)
fi
fi
fi
AM_CONDITIONAL(BUILD_GIF_LOADER, test "$gif_ok" = yes)
AC_SUBST(GIFLIBS)
AC_CHECK_LIB(z, uncompress,
zlib_ok=yes,
zlib_ok=no
AC_MSG_WARN(*** Native zlib support will not be built (zlib not found) ***),
)
if test "$zlib_ok" = yes; then
AC_MSG_CHECKING([for zlib.h])
AC_TRY_CPP(
[#include <stdio.h>
#undef PACKAGE
#undef VERSION
#include <zlib.h>],
zlib_ok=yes,
zlib_ok=no)
AC_MSG_RESULT($zlib_ok)
if test "$zlib_ok" = yes; then
ZLIBLIBS="-lz"
else
AC_MSG_WARN(*** Native zlib support will not be built (zlib header file not found) ***)
fi
fi
AM_CONDITIONAL(BUILD_ZLIB_LOADER, test "$zlib_ok" = yes)
AC_SUBST(ZLIBLIBS)
AC_CHECK_LIB(bz2, BZ2_bzRead,
bz2_ok=yes,
bz2_ok=no
AC_MSG_WARN(*** Native bz2 support will not be built (bzip2 library not found) ***),
)
if test "$bz2_ok" = yes; then
AC_MSG_CHECKING([for bzlib.h])
AC_TRY_CPP(
[#include <stdio.h>
#undef PACKAGE
#undef VERSION
#include <bzlib.h>],
bz2_ok=yes,
bz2_ok=no)
AC_MSG_RESULT($bz2_ok)
if test "$bz2_ok" = yes; then
BZ2LIBS="-lbz2"
else
AC_MSG_WARN(*** Native bz2 support will not be built (bzip2 header file not found) ***)
fi
fi
AM_CONDITIONAL(BUILD_BZ2_LOADER, test "$bz2_ok" = yes)
AC_SUBST(BZ2LIBS)
AC_OUTPUT([
Makefile
src/Makefile
src/lib/Makefile
src/bin/Makefile
src/modules/Makefile
src/modules/filters/Makefile
src/modules/loaders/Makefile
data/Makefile
data/fonts/Makefile
data/images/Makefile
doc/Makefile
debian/Makefile
imlib2-config
imlib2.pc
],[
chmod +x imlib2-config
touch imlib2_docs.tar.gz
])

2
data/Makefile.am Normal file
View File

@ -0,0 +1,2 @@
MAINTAINERCLEANFILES = Makefile.in
SUBDIRS = fonts images

11
data/fonts/Makefile.am Normal file
View File

@ -0,0 +1,11 @@
MAINTAINERCLEANFILES = Makefile.in
FILES = \
cinema.ttf \
grunge.ttf \
morpheus.ttf \
notepad.ttf
filesdir = $(pkgdatadir)/data/fonts
files_DATA = $(FILES)
EXTRA_DIST = $(FILES)

BIN
data/fonts/cinema.ttf Normal file

Binary file not shown.

BIN
data/fonts/grunge.ttf Normal file

Binary file not shown.

BIN
data/fonts/morpheus.ttf Normal file

Binary file not shown.

BIN
data/fonts/notepad.ttf Normal file

Binary file not shown.

25
data/images/Makefile.am Normal file
View File

@ -0,0 +1,25 @@
MAINTAINERCLEANFILES = Makefile.in
FILES = \
audio.png \
bg.png \
bulb.png \
cal.png \
calc.png \
folder.png \
globe.png \
imlib2.png \
lock.png \
mail.png \
menu.png \
mush.png \
paper.png \
sh1.png \
sh2.png \
sh3.png \
stop.png \
tnt.png
filesdir = $(pkgdatadir)/data/images
files_DATA = $(FILES)
EXTRA_DIST = $(FILES)

BIN
data/images/audio.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
data/images/bg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

BIN
data/images/bulb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
data/images/cal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

BIN
data/images/calc.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
data/images/folder.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
data/images/globe.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
data/images/imlib2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

BIN
data/images/lock.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

BIN
data/images/mail.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
data/images/menu.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
data/images/mush.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
data/images/paper.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
data/images/sh1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 768 B

BIN
data/images/sh2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 280 B

BIN
data/images/sh3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 360 B

BIN
data/images/stop.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

BIN
data/images/tnt.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

9
debian/Makefile.am vendored Normal file
View File

@ -0,0 +1,9 @@
EXTRA_DIST = \
changelog \
control \
copyright \
imlib2-config.1 \
libimlib2-dev.doc-base \
libimlib2.files \
libimlib2-dev.files \
rules

5
debian/changelog vendored Normal file
View File

@ -0,0 +1,5 @@
imlib2 (1.1.2-0cvs20040918) unstable; urgency=low
* a CVS release
-- Sytse Wielinga <s.b.wielinga@student.utwente.nl> Sat, 18 Sep 2004 12:48:44 +0200

44
debian/control vendored Normal file
View File

@ -0,0 +1,44 @@
Source: imlib2
Section: libs
Priority: optional
Maintainer: Laurence J. Lane <ljlane@debian.org>
Build-Depends: libjpeg62-dev, libttf-dev, libpng3-dev | libpng2-dev | libpng-dev, libtiff4-dev | libtiff-dev, zlib1g-dev, libungif4-dev | libungif3g-dev | giflib3g-dev, xlibs-dev, libfreetype6-dev | freetype2-dev, libbz2-dev, libltdl3-dev, automake1.7 | automaken, libtool, debhelper (>= 4.0)
Standards-Version: 3.5.7.0
Package: imlib2-demo
Architecture: any
Section: graphics
Depends: ${shlibs:Depends}
Description: Imlib2 demo's
This package contains two small Imlib2-based programs: a simple
image viewer and a simple image conversion program.
Package: imlib2-test
Architecture: any
Section: graphics
Depends: ${shlibs:Depends}
Description: Imlib2 test programs
This package contains some, not generally usable, test programs
for Imlib2.
Package: libimlib2
Section: libs
Architecture: any
Depends: ${shlibs:Depends}
Suggests: imlib2-loaders, imlib2-demo (= ${Source-Version})
Description: Powerful image loading and rendering library
Imlib2 is an advanced replacement library for libraries like
libXpm that provides many more features with much greater
flexibility and speed than standard libraries, including font
rasterization, rotation, RGBA space rendering and blending,
dynamic binary filters, scripting, and more.
.
Imlib2 is not a drop-in replacement for Imlib 1.x.
Package: libimlib2-dev
Architecture: any
Section: devel
Architecture: any
Depends: libimlib2 (= ${Source-Version}), libc6-dev | libc-dev, libjpeg62-dev, libpng3-dev | libpng2-dev | libpng-dev, libtiff4-dev | libtiff-dev, zlib1g-dev, libttf-dev, libungif4-dev | libungif3g-dev | giflib3g-dev, xlibs-dev, libfreetype6-dev | freetype2-dev, libbz2-dev
Description: Imlib2 headers, static libraries and documentation
Headers, static libraries and documentation for Imlib2.

32
debian/copyright vendored Normal file
View File

@ -0,0 +1,32 @@
This package was debianized by Laurence J. Lane <ljlane@debian.org> on
Sat, 28 Oct 2000 17:56:46 -0400.
The source code is from the e17/libs/imlib2 module of the enlightenment CVS
tree. For more information, see:
http://www.enlightenment.org/cvs.html
Upstream Author: Carsten Haitzler <raster@rasterman.com>
Copyright:
Copyright (C) 2000 Carsten Haitzler and various contributors (see AUTHORS)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies of the Software, its documentation and marketing & publicity
materials, and acknowledgment shall be given in the documentation, materials
and software packages that this Software was used.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

17
debian/imlib2-config.1 vendored Normal file
View File

@ -0,0 +1,17 @@
.TH imlib2-config 1 "29 Oct 2000" imlib2-config
.SH NAME
.HP
imlib2-config - imlib2 build information script
.SH SYNOPSIS
.HP
imlib2-config [options]
.P
.SH DESCRIPTION
.HP
.I imlib2-config
is a script that's used by make and other build enviroments to
gather imlib2 information.
.HP
Run
.I imlib2-config
for additional information.

2
debian/imlib2-demo.install vendored Normal file
View File

@ -0,0 +1,2 @@
usr/bin/imconvert
usr/bin/imlib2_view

5
debian/imlib2-test.install vendored Normal file
View File

@ -0,0 +1,5 @@
usr/bin/imlib2
usr/bin/imlib2_test
usr/bin/bumpmaptest
usr/bin/color_spaces
usr/bin/polytest

10
debian/libimlib2-dev.doc-base vendored Normal file
View File

@ -0,0 +1,10 @@
Document: imlib2
Title: Imlib2 Guide
Author: Carsten Haitzler
Abstract: This document describes Imlib2 API
and provides sample C code.
Section: Apps/Programming
Format: HTML
Index: /usr/share/doc/libimlib2-dev/html/index.html
Files: /usr/share/doc/libimlib2-dev/html/index.html

10
debian/libimlib2-dev.install vendored Normal file
View File

@ -0,0 +1,10 @@
usr/bin/imlib2-config
usr/lib/pkgconfig/*
usr/include
usr/lib/*.so
usr/lib/*.a
usr/lib/*.la
usr/lib/imlib2_loaders/filter/*.a
usr/lib/imlib2_loaders/filter/*.la
usr/lib/imlib2_loaders/image/*.a
usr/lib/imlib2_loaders/image/*.la

3
debian/libimlib2.install vendored Normal file
View File

@ -0,0 +1,3 @@
usr/lib/*.so.*
usr/lib/imlib2_loaders/filter/*.so
usr/lib/imlib2_loaders/image/*.so

88
debian/rules vendored Normal file
View File

@ -0,0 +1,88 @@
#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
# This is the debhelper compatability version to use.
export DH_COMPAT=4
# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
CFLAGS ?= -Wall -g
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
CFLAGS += -O0
else
CFLAGS += -O2
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
INSTALL_PROGRAM += -s
endif
ifneq (,$(findstring mmx,$(DEB_BUILD_OPTIONS)))
ENABLE_MMX = yes
else
ENABLE_MMX = no
endif
INSTALL=/usr/bin/install -p
CONFIGUREOPTS = --prefix=/usr --enable-mmx=$(ENABLE_MMX) --build=$(DEB_BUILD_GNU_TYPE) --host=$(DEB_HOST_GNU_TYPE)
package=libimlib2
configure: configure-stamp
configure-stamp:
test -x autogen.sh && ./autogen.sh $(CONFIGUREOPTS) || ./configure $(CONFIGUREOPTS)
touch configure-stamp
build: build-stamp
build-stamp: configure-stamp
dh_testdir
$(MAKE)
touch build-stamp
clean:
dh_testdir
rm -f build-stamp configure-stamp
-$(MAKE) distclean
dh_clean
install: build
dh_testdir
dh_testroot
dh_clean -k
dh_installdirs
$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp/
$(INSTALL) -d debian/$(package)-dev/usr/share/doc/$(package)-dev/html
$(INSTALL) -m 644 doc/*.html doc/*.gif \
debian/$(package)-dev/usr/share/doc/$(package)-dev/html
binary-indep: build install
binary-arch: build install
dh_testdir
dh_testroot
dh_install --sourcedir=debian/tmp --list-missing
dh_installdocs AUTHORS README
dh_installchangelogs
dh_link
dh_strip
dh_compress
dh_fixperms
dh_makeshlibs
dh_installdeb
dh_shlibdeps
dh_gencontrol
dh_md5sums
dh_builddeb
binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure

5
doc/Makefile.am Normal file
View File

@ -0,0 +1,5 @@
MAINTAINERCLEANFILES = Makefile.in
EXTRA_DIST = imlib2.gif \
blank.gif \
index.html

BIN
doc/blank.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 B

2
doc/foot.html Normal file
View File

@ -0,0 +1,2 @@
</body>
</html>

19
doc/head.html Normal file
View File

@ -0,0 +1,19 @@
<html>
<head>
<title>$title</title>
<link href=imlib2.css rel=stylesheet type=text/css>
</head>
<body>
<div class=nav>
<table border=0 align=center><tr>
<td width=16><img src=imlib2_mini.png width=16 height=16 alt=E></td>
<td width=100% align=center>
I : M : L : I : B : 2
</td>
<td width=16><img src=imlib2_mini.png width=16 height=16 alt=E></td>
</tr></table>
</div>

BIN
doc/img/hilite.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

BIN
doc/img/imlib2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

BIN
doc/img/imlib2_mini.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 753 B

178
doc/imlib2.css Normal file
View File

@ -0,0 +1,178 @@
td.md {
background-color: #ffffff;
font-family: monospace;
text-align: left;
vertical-align: center;
font-size: 10;
padding-right : 1px;
padding-top : 1px;
padding-left : 1px;
padding-bottom : 1px;
margin-left : 1px;
margin-right : 1px;
margin-top : 1px;
margin-bottom : 1px
}
td.mdname {
font-family: monospace;
text-align: left;
vertical-align: center;
font-size: 10;
padding-right : 1px;
padding-top : 1px;
padding-left : 1px;
padding-bottom : 1px;
margin-left : 1px;
margin-right : 1px;
margin-top : 1px;
margin-bottom : 1px
}
h1
{
text-align: center;
color: #333333
}
h2
{
text-align: left;
color: #333333
}
h3
{
text-align: left;
color: #333333
}
a:link
{
text-decoration: none;
color: #444444;
font-weight: bold;
}
a:visited
{
text-decoration: none;
color: #666666;
font-weight: bold;
}
a:hover
{
text-decoration: none;
color: #000000;
font-weight: bold;
}
a.nav:link
{
text-decoration: none;
color: #444444;
font-weight: normal;
}
a.nav:visited
{
text-decoration: none;
color: #666666;
font-weight: normal;
}
a.nav:hover
{
text-decoration: none;
color: #000000;
font-weight: normal;
}
a.qindex:link
{
text-decoration: none;
color: #444444;
font-weight: normal;
}
a.qindex:visited
{
text-decoration: none;
color: #666666;
font-weight: normal;
}
a.qindex:hover
{
text-decoration: none;
color: #000000;
font-weight: normal;
}
p
{
color: #000000;
font-family: sans-serif;
font-size: 10;
}
body {
background-image: url("hilite.png");
background-repeat: no-repeat;
background-position: left top;
background-color: #dddddd;
color: #000000;
font-family: sans-serif;
padding: 8px;
margin: 0;
}
div.fragment
{
background-image: url("hilite.png");
background-repeat: no-repeat;
background-position: left top;
border: thin solid #888888;
background-color: #eeeeee;
padding: 4px;
text-align: left;
vertical-align: center;
font-size: 12;
}
hr
{
border: 0;
background-color: #000000;
width: 80%;
height: 1;
}
dl
{
background-image: url("hilite.png");
background-repeat: no-repeat;
background-position: left top;
border: thin solid #aaaaaa;
background-color: #eeeeee;
padding: 4px;
text-align: left;
vertical-align: center;
font-size: 12;
}
em
{
color: #334466;
font-family: courier;
font-size: 10;
font-style: normal;
}
div.nav
{
border: thin solid #000000;
background-color: #ffffff;
padding: 1px;
text-align: center;
vertical-align: center;
font-size: 12;
}
div.body
{
border: thin solid #000000;
background-color: #ffffff;
padding: 4px;
text-align: left;
font-size: 10;
}
div.diag
{
border: thin solid #888888;
background-color: #eeeeee;
padding: 4px;
text-align: center;
font-size: 8;
}

BIN
doc/imlib2.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

2268
doc/index.html Normal file

File diff suppressed because it is too large Load Diff

17
gendoc Executable file
View File

@ -0,0 +1,17 @@
#!/bin/sh
cp ./imlib2.c.in ./imlib2.c
for I in `find ./src -name "api.c" -print`; do
cat $I >> ./imlib2.c
done
#for I in `find ./src/lib -name "*.c" -print`; do
# cat $I >> ./imlib2.c
#done
rm -rf ./doc/html ./doc/latex ./doc/man
doxygen
cp doc/img/*.png doc/html/
rm -f imlib2_docs.tar imlib2_docs.tar.gz
tar -cvf imlib2_docs.tar doc/html doc/man doc/latex
gzip -9 imlib2_docs.tar
exit 0

59
imlib2-config.in Normal file
View File

@ -0,0 +1,59 @@
#!/bin/sh
prefix=@prefix@
exec_prefix=@exec_prefix@
exec_prefix_set=no
usage="\
Usage: imlib2-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--libs] [--cflags]"
if test $# -eq 0; then
echo "${usage}" 1>&2
exit 1
fi
while test $# -gt 0; do
case "$1" in
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg= ;;
esac
case $1 in
--prefix=*)
prefix=$optarg
if test $exec_prefix_set = no ; then
exec_prefix=$optarg
fi
;;
--prefix)
echo $prefix
;;
--exec-prefix=*)
exec_prefix=$optarg
exec_prefix_set=yes
;;
--exec-prefix)
echo $exec_prefix
;;
--version)
echo @VERSION@
;;
--cflags)
if test @includedir@ != /usr/include ; then
includes=-I@includedir@
fi
echo $includes
;;
--libs)
libdirs=-L@libdir@
echo $libdirs -lImlib2 @my_libs@
;;
*)
echo "${usage}" 1>&2
exit 1
;;
esac
shift
done
exit 0

547
imlib2.c.in Normal file
View File

@ -0,0 +1,547 @@
/**
@file
@brief Imlib2 library
Brief of imlib2 library
*/
/**
@mainpage Imlib2 Library Documentation
@image html imlib2.png
@version 1.1.1
@author Carsten Haitzler <raster@rasterman.com>
@date 1999-2004
@section intro What is Imlib2 ?
Imlib 2 is the successor to Imlib. It is NOT a newer version - it is a completely new library. Imlib 2 can be installed alongside Imlib 1.x without any problems since they are effectively different libraries - BUT they Have very similar functionality.
Imlib 2 does the following:
\li Load image files from disk in one of many formats
\li Save images to disk in one of many formats
\li Render image data onto other images
\li Render images to an X-Windows drawable
\li Produce pixmaps and pixmap masks of Images
\li Apply filters to images
\li Rotate images
\li Accept RGBA Data for images
\li Scale images
\li Alpha blend Images on other images or drawables
\li Apply color correction and modification tables and factors to images
\li Render images onto images with color correction and modification tables
\li Render truetype anti-aliased text
\li Render truetype anti-aliased text at any angle
\li Render anti-aliased lines
\li Render rectangles
\li Render linear multi-colored gradients
\li Cache data intelligently for maximum performance
\li Allocate colors automatically
\li Allow full control over caching and color allocation
\li Provide highly optimized MMX assembly for core routines
\li Provide plug-in filter interface
\li Provide on-the-fly runtime plug-in image loading and saving interface
\li Fastest image compositing, rendering and manipulation library for X
If what you want isn't in the list above somewhere then likely Imlib 2 does not do it. If it does it it likely does it faster than any other library you can find (this includes gdk-pixbuf, gdkrgb, etc.) primarily because of highly optimized code and a smart subsystem that does the dirty work for you and picks up the pieces for you so you can be lazy and let all the optimizations for FOR you.
Imlib 2 can run without a display, so it can be easily used for background image processing for web sites or servers - it only requires the X libraries to be installed - that is all - it does not require an XServer to run unless you wish to display images.
The interface is simple - once you get used to it, the functions do exactly what they say they do.
@section first_ex A Simple Example
The best way to start is to show a simple example of an Imlib2
program. This one will load an image of any format you have a loader
installed for (all loaders are dynamic code objects that Imlib2 will
use and update automatically runtime - anyone is free to write a
loader. All that has to be done is for the object to be dropped into
the loaders directory with the others and all Imlib2 programs will
automatically be able to use it - without a restart).
@code
/* main program */
int main(int argc, char **argv)
{
/* an image handle */
Imlib_Image image;
/* if we provided < 2 arguments after the command - exit */
if (argc != 3) exit(1);
/* load the image */
image = imlib_load_image(argv[1]);
/* if the load was successful */
if (image)
{
char *tmp;
/* set the image we loaded as the current context image to work on */
imlib_context_set_image(image);
/* set the image format to be the format of the extension of our last */
/* argument - i.e. .png = png, .tif = tiff etc. */
tmp = strrchr(argv[2], '.');
if(tmp)
imlib_image_set_format(tmp + 1);
/* save the image */
imlib_save_image(argv[2]);
}
}
@endcode
Now to compile this
@verbatim
cc imlib2_convert.c -o imlib2_convert `imlib2-config --cflags` `imlib2-config --libs`
@endverbatim
You now have a program that if used as follows:
@verbatim
cc imlib2_con
./imlib2_convert image1.jpg image2.png
@endverbatim
will convert image1.jpg into a png called image2.png. It is that simple.
@section loading How Image Loading Works
It is probably a good idea to discuss how Imlib2 actually loads an Image so the programmer knows what is going on, how to take advantage of the optimizations already there and to explain why things work as they do.
@subsection load_func Loading using imlib_load_image();
This is likely to be by far the most common way to load an image - when you don't really care about the details of the loading process or why it failed - all you care about is if you got a valid image handle.
When you call this function Imlib2 attempts to find the file specified as the parameter. This will involve Imlib2 first checking to see if that file path already has been loaded and is in Imlib2's cache (a cache of already decoded images in memory to save having to load and decode from disk all the time). If there already is a copy in the cache (either already active or speculatively cached from a previous load & free) this copy will have its handle returned instead of Imlib2 checking on disk (in some circumstances this is not true - see later in this section to find out). This means if your program blindly loads an Image, renders it, then frees it - then soon afterwards loads the same image again, it will not be loaded from disk at all, instead it will simply be re-referenced from the cache - meaning the load will be almost instant. A great way to take full advantage of this is to set the cache to some size you are happy with for the image data being used by your application and then all rendering o an image follows the pseudo code:
@verbatim
set cache to some amount (e.g. 4 Mb)
...
rendering loop ...
load image
render image
free image
... continue loop
@endverbatim
This may normally sound silly - load image, render then free - EVERY time we want to use it, BUT - it is actually the smartest way to use Imlib2 - since the caching will find the image for you in the cache - you do not need to manage your own cache, or worry about filling up memory with image data - only as much memory as you have set for the cache size will actually ever be used to store image data - if you have lots of image data to work with then increase the cache size for better performance, but this is the only thing you need to worry about. you won't have problems of accidentally forgetting to free images later since you free them immediately after use.
Now what happens if the file changes on disk while it's in cache? By default nothing. The file is ignored. This is an optimization (to avoid hitting the disk to check if the file changed for every load if it's cached). You can inform Imlib2 that you care about this by using the imlib_image_set_changes_on_disk(); call. Do this whenever you load an Image that you expect will change on disk, and the fact that it changes really matters. Remember this will marginally reduce the caching performance.
Now what actually happens when we try and load an image using a
filename? First the filename is broken down into 2 parts. the filename
before a colon (:) and the key after the colon. This means when we
have a filename like:
@verbatim
/path/to/file.jpg
@endverbatim
the filename is:
@verbatim
/path/to/file.jpg
@endverbatim
and the key is blank. If we have:
@verbatim
/path/to/file.db:key.value/blah
@endverbatim
the filename is:
@verbatim
/path/to/file.db
@endverbatim
and the key is:
@verbatim
key.value/blah
@endverbatim
You may ask what is this thing with keys and filenames? Well Imlib2 has loaders that are able to load data that is WITHIN a file (the loader capable of this right now is the database loader that is able to load image data stored with a key in a Berkeley-db database file). The colon is used to delimit where the filename ends and the key begins. Fro the majority of files you load you won't have to worry, but there is a limit in this case that filenames cannot contain a color character.
First Imlib2 checks to see if the file exists and that you have permission to read it. If this fails it will abort the load. Now that it has checked that this is the case it evaluates that it's list of dynamically loaded loader modules it up to date then it runs through the loader modules until one of them claims it can load this file. If this is the case that loader is now used to decode the image and return an Image handle to the calling program. If the loader is written correctly and the file format sanely supports this, the loader will NOT decode any image data at this point. It will ONLY read the header of the image to figure out its size, if it has an alpha channel, format and any other header information. The loader is remembered and it will be re-used to load the image data itself later if and ONLY if the actual image data itself is needed. This means you can scan vast directories of files figuring their format and size and other such information just by loading and freeing - and it will be fast because no image data is decoded. You can take advantage of this by loading the image and checking its size to calculate the size of an output area before you ever load the data. This means geometry calculations can be done fast ahead of time.
If you desire more detailed information about why a load failed you can use imlib_load_image_with_error_return(); and it will return a detailed error return code.
If you do not wish to have the image data loaded later using the optimized "deferred" method of loading, you can force the data to be decoded immediately with imlib_load_image_immediately();
If you wish to bypass the cache when loading images you can using imlib_load_image_without_cache(); and imlib_load_image_immediately_without_cache();.
Sometimes loading images can take a while. Often it is a good idea to provide feedback to the user whilst this is happening. This is when you set the progress function callback. Setting this to NULL will mean no progress function is called during load - this is the default. When it is set you set it to a function that will get called every so often (depending on the progress granularity) during load. Use imlib_context_set_progress_function(); and imlib_context_set_progress_granularity(); to set this up.
@section second_ex A more advanced Example
This is a more comprehensive example that should show off a fair number of features of imlib2. The code this was based off can be found in Imlib2's test directory. This covers a lot of the core of Imlib2's API so you should have a pretty good idea on how it works if you understand this code snippet.
@code
/* include X11 stuff */
#include <X11/Xlib.h>
/* include Imlib2 stuff */
#include <Imlib2.h>
/* sprintf include */
#include <stdio.h>
/* some globals for our window & X display */
Display *disp;
Window win;
Visual *vis;
Colormap cm;
int depth;
/* the program... */
int main(int argc, char **argv)
{
/* events we get from X */
XEvent ev;
/* areas to update */
Imlib_Updates updates, current_update;
/* our virtual framebuffer image we draw into */
Imlib_Image buffer;
/* a font */
Imlib_Font font;
/* our color range */
Imlib_Color_Range range;
/* our mouse x, y coordinates */
int mouse_x = 0, mouse_y = 0;
/* connect to X */
disp = XOpenDisplay(NULL);
/* get default visual , colormap etc. you could ask imlib2 for what it */
/* thinks is the best, but this example is intended to be simple */
vis = DefaultVisual(disp, DefaultScreen(disp));
depth = DefaultDepth(disp, DefaultScreen(disp));
cm = DefaultColormap(disp, DefaultScreen(disp));
/* create a window 640x480 */
win = XCreateSimpleWindow(disp, DefaultRootWindow(disp),
0, 0, 640, 480, 0, 0, 0);
/* tell X what events we are interested in */
XSelectInput(disp, win, ButtonPressMask | ButtonReleaseMask |
PointerMotionMask | ExposureMask);
/* show the window */
XMapWindow(disp, win);
/* set our cache to 2 Mb so it doesn't have to go hit the disk as long as */
/* the images we use use less than 2Mb of RAM (that is uncompressed) */
imlib_set_cache_size(2048 * 1024);
/* set the font cache to 512Kb - again to avoid re-loading */
imlib_set_font_cache_size(512 * 1024);
/* add the ./ttfonts dir to our font path - you'll want a notepad.ttf */
/* in that dir for the text to display */
imlib_add_path_to_font_path("./ttfonts");
/* set the maximum number of colors to allocate for 8bpp and less to 128 */
imlib_set_color_usage(128);
/* dither for depths < 24bpp */
imlib_context_set_dither(1);
/* set the display , visual, colormap and drawable we are using */
imlib_context_set_display(disp);
imlib_context_set_visual(vis);
imlib_context_set_colormap(cm);
imlib_context_set_drawable(win);
/* infinite event loop */
for (;;)
{
/* image variable */
Imlib_Image image;
/* width and height values */
int w, h, text_w, text_h;
/* init our updates to empty */
updates = imlib_updates_init();
/* while there are events form X - handle them */
do
{
XNextEvent(disp, &ev);
switch (ev.type)
{
case Expose:
/* window rectangle was exposed - add it to the list of */
/* rectangles we need to re-render */
updates = imlib_update_append_rect(updates,
ev.xexpose.x, ev.xexpose.y,
ev.xexpose.width, ev.xexpose.height);
break;
case ButtonPress:
/* if we click anywhere in the window, exit */
exit(0);
break;
case MotionNotify:
/* if the mouse moves - note it */
/* add a rectangle update for the new mouse position */
image = imlib_load_image("./test_images/mush.png");
imlib_context_set_image(image);
w = imlib_image_get_width();
h = imlib_image_get_height();
imlib_context_set_image(image);
imlib_free_image();
/* the old position - so we wipe over where it used to be */
updates = imlib_update_append_rect(updates,
mouse_x - (w / 2), mouse_y - (h / 2),
w, h);
font = imlib_load_font("notepad/30");
if (font)
{
char text[4096];
imlib_context_set_font(font);
sprintf(text, "Mouse is at %i, %i", mouse_x, mouse_y);
imlib_get_text_size(text, &text_w, &text_h);
imlib_free_font();
updates = imlib_update_append_rect(updates,
320 - (text_w / 2), 240 - (text_h / 2),
text_w, text_h);
}
mouse_x = ev.xmotion.x;
mouse_y = ev.xmotion.y;
/* the new one */
updates = imlib_update_append_rect(updates,
mouse_x - (w / 2), mouse_y - (h / 2),
w, h);
font = imlib_load_font("notepad/30");
if (font)
{
char text[4096];
imlib_context_set_font(font);
sprintf(text, "Mouse is at %i, %i", mouse_x, mouse_y);
imlib_get_text_size(text, &text_w, &text_h);
imlib_free_font();
updates = imlib_update_append_rect(updates,
320 - (text_w / 2), 240 - (text_h / 2),
text_w, text_h);
}
default:
/* any other events - do nothing */
break;
}
}
while (XPending(disp));
/* no more events for now ? ok - idle time so lets draw stuff */
/* take all the little rectangles to redraw and merge them into */
/* something sane for rendering */
updates = imlib_updates_merge_for_rendering(updates, 640, 480);
for (current_update = updates;
current_update;
current_update = imlib_updates_get_next(current_update))
{
int up_x, up_y, up_w, up_h;
/* find out where the first update is */
imlib_updates_get_coordinates(current_update,
&up_x, &up_y, &up_w, &up_h);
/* create our buffer image for rendering this update */
buffer = imlib_create_image(up_w, up_h);
/* we can blend stuff now */
imlib_context_set_blend(1);
/* fill the window background */
/* load the background image - you'll need to have some images */
/* in ./test_images lying around for this to actually work */
image = imlib_load_image("./test_images/bg.png");
/* we're working with this image now */
imlib_context_set_image(image);
/* get its size */
w = imlib_image_get_width();
h = imlib_image_get_height();
/* now we want to work with the buffer */
imlib_context_set_image(buffer);
/* if the iimage loaded */
if (image)
{
/* blend image onto the buffer and scale it to 640x480 */
imlib_blend_image_onto_image(image, 0,
0, 0, w, h,
- up_x, - up_y, 640, 480);
/* working with the loaded image */
imlib_context_set_image(image);
/* free it */
imlib_free_image();
}
/* draw an icon centered around the mouse position */
image = imlib_load_image("./test_images/mush.png");
imlib_context_set_image(image);
w = imlib_image_get_width();
h = imlib_image_get_height();
imlib_context_set_image(buffer);
if (image)
{
imlib_blend_image_onto_image(image, 0,
0, 0, w, h,
mouse_x - (w / 2) - up_x, mouse_y - (h / 2) - up_y, w, h);
imlib_context_set_image(image);
imlib_free_image();
}
/* draw a gradient on top of things at the top left of the window */
/* create a range */
range = imlib_create_color_range();
imlib_context_set_color_range(range);
/* add white opaque as the first color */
imlib_context_set_color(255, 255, 255, 255);
imlib_add_color_to_color_range(0);
/* add an orange color, semi-transparent 10 units from the first */
imlib_context_set_color(255, 200, 10, 100);
imlib_add_color_to_color_range(10);
/* add black, fully transparent at the end 20 units away */
imlib_context_set_color(0, 0, 0, 0);
imlib_add_color_to_color_range(20);
/* draw the range */
imlib_context_set_image(buffer);
imlib_image_fill_color_range_rectangle(- up_x, - up_y, 128, 128, -45.0);
/* free it */
imlib_free_color_range();
/* draw text - centered with the current mouse x, y */
font = imlib_load_font("notepad/30");
if (font)
{
char text[4096];
/* set the current font */
imlib_context_set_font(font);
/* set the image */
imlib_context_set_image(buffer);
/* set the color (black) */
imlib_context_set_color(0, 0, 0, 255);
/* print text to display in the buffer */
sprintf(text, "Mouse is at %i, %i", mouse_x, mouse_y);
/* query the size it will be */
imlib_get_text_size(text, &text_w, &text_h);
/* draw it */
imlib_text_draw(320 - (text_w / 2) - up_x, 240 - (text_h / 2) - up_y, text);
/* free the font */
imlib_free_font();
}
/* don't blend the image onto the drawable - slower */
imlib_context_set_blend(0);
/* set the buffer image as our current image */
imlib_context_set_image(buffer);
/* render the image at 0, 0 */
imlib_render_image_on_drawable(up_x, up_y);
/* don't need that temporary buffer image anymore */
imlib_free_image();
}
/* if we had updates - free them */
if (updates)
imlib_updates_free(updates);
/* loop again waiting for events */
}
return 0;
}
@endcode
@section filters Imlib2 filters
@subsection dyn_filter Imlib 2 Dynamic Filters
Imlib2 has built in features allowing filters and effects to be applied at run time through a very small scripting language, this is similar to that of script-fu found in the GIMP (http://www.gimp.org). There are two parts to the system, the client library call ``imlib_apply_filter'' and the library side filters. The library side filters are synonymous with image loaders.
To run a script on an image you need to set the context image then call:
@verbatim
imlib_apply_filter( script_string, ... );
@endverbatim
The script_string variable is made up of the script language, which is very simple and made up of only function calls. Functions calls look like this:
@verbatim
filter name( key=value [, ...] );
@endverbatim
Where,
\li <b>filter name</b> is the name of the filter you wish to apply
\li \b key is an expected value
\li \b value is a ``string'', a number, or an actual variable in
the program, or the result of another filter.
eg.
@verbatim
bump_map( map=tint(red=50,tint=200), blue=10 );
@endverbatim
This example would bump map using a a map generated from the tint filter.
It is also possible to pass application information to the filters via the usage of the [] operator. When the script is being compiled the script engine looks on the parameters passed to it and picks up a pointer for every [] found.
eg2.
@verbatim
imlib_apply_filter( "tint( x=[], y=[], red=255, alpha=55 );", &myxint, &myyint );
@endverbatim
This will cause a tint to the current image at (myxint,myyint) to be done. This is very useful for when you want the filters to dynamically change according to program variables. The system is very quick as the code is pseudo-compiled and then run. The advantage of having the scripting system allows customization of the image manipulations, this is particularly useful in applications that allow modifications to be done (eg. image viewers).
@subsection lib_filter Filter Library
There are three functions that must be in every filter library
@code
void init( struct imlib_filter_info *info ); - Called once on loading of the filter
@endcode
info - a structure passed to the filter to be filled in with information about the filter info->name - Name of the filter library
info->author - Name of the library author
info->description - Description of the filter library
info->num_filters - Number of filters the library exports
info->filters - An array of ``char *'' with each filter name in it.
@code
void deinit(); - Called when the filter is closed
/* Called every time a filter the library exports is called */
void *exec( char *filter, void *im, pIFunctionParam params );
@endcode
filter - The name of the filter being asked for im - The image that the filter should be applied against params - A linked list of parameters.
The best way to get all the values is such:
Declare all parameters and initialize them to there default values.
@code
for( ptr = params; ptr != NULL; ptr = ptr->next )
{
..MACRO TO GET VALUE..
}
@endcode
Current Macros are:
@verbatim
ASSIGN_INT( keyname, local variable )
ASSIGN_DATA8( keyname, local variable )
ASSIGN_IMAGE( keyname, local variable )
@endverbatim
eg.
@code
int r = 50;
IFunctionParam *ptr;
for( ptr = params; ptr != NULL; ptr = ptr->next )
{
ASSIGN_INT( "red", r );
}
@endcode
If the value "red" is not passed to the filter then it will remain at 50, but it a value is passed, it will be assign to r.
return type - Imlib_Image, this is the result of filter.
@todo line code doesnt draw nice liens when clipping - fix
@todo filled polygons can break fill bounds on corner cases - fix
@todo go thru TODOs and FIXMEs
*/

12
imlib2.pc.in Normal file
View File

@ -0,0 +1,12 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: imlib2
Description: Powerful image loading and rendering library
Requires: @requirements@
Version: @VERSION@
Libs: -L${libdir} -lImlib2
Cflags: -I${includedir}

184
imlib2.spec Normal file
View File

@ -0,0 +1,184 @@
Summary: Powerful image loading and rendering library
Name: imlib2
Version: 1.2.0
Release: 1.%(date '+%Y%m%d')
Copyright: BSD
Group: System Environment/Libraries
Source: ftp://ftp.enlightenment.org/pub/enlightenment/e17/libs/%{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-root
Packager: Michael Jennings <mej@eterm.org>
URL: http://www.rasterman.com/raster/imlib.html
#BuildSuggests: freetype-devel xorg-x11-devel
Requires: %{name}-loader_jpeg = %{version}
Requires: %{name}-loader_png = %{version}
Requires: %{name}-loader_argb = %{version}
%description
Imlib2 is an advanced replacement library for libraries like libXpm that
provides many more features with much greater flexibility and speed than
standard libraries, including font rasterization, rotation, RGBA space
rendering and blending, dynamic binary filters, scripting, and more.
%package devel
Summary: Imlib2 headers, static libraries and documentation
Group: System Environment/Libraries
Requires: %{name} = %{version}
%description devel
Headers, static libraries and documentation for Imlib2.
%package filters
Summary: Imlib2 basic plugin filters set
Group: System Environment/Libraries
Requires: %{name} = %{version}
%description filters
Basic set of plugin filters that come with Imlib2
%package loader_lbm
Summary: Imlib2 LBM loader
Group: System Environment/Libraries
%description loader_lbm
LBM image loader/saver for Imlib2
%package loader_jpeg
Summary: Imlib2 JPEG loader
Group: System Environment/Libraries
BuildRequires: libjpeg-devel
%description loader_jpeg
JPEG image loader/saver for Imlib2
%package loader_png
Summary: Imlib2 PNG loader
Group: System Environment/Libraries
BuildRequires: libpng-devel
BuildRequires: zlib-devel
%description loader_png
PNG image loader/saver for Imlib2
%package loader_argb
Summary: Imlib2 ARGB loader
Group: System Environment/Libraries
%description loader_argb
ARGB image loader/saver for Imlib2
%package loader_bmp
Summary: Imlib2 BMP loader
Group: System Environment/Libraries
%description loader_bmp
BMP image loader/saver for Imlib2
%package loader_gif
Summary: Imlib2 GIF loader
Group: System Environment/Libraries
%description loader_gif
GIF image loader for Imlib2
%package loader_pnm
Summary: Imlib2 PNM loader
Group: System Environment/Libraries
%description loader_pnm
PNM image loader/saver for Imlib2
%package loader_tga
Summary: Imlib2 TGA loader
Group: System Environment/Libraries
%description loader_tga
TGA image loader/saver for Imlib2
%package loader_tiff
Summary: Imlib2 TIFF loader
Group: System Environment/Libraries
BuildRequires: libtiff-devel
%description loader_tiff
TIFF image loader/saver for Imlib2
%package loader_xpm
Summary: Imlib2 XPM loader
Group: System Environment/Libraries
%description loader_xpm
XPM image loader/saver for Imlib2
%package loader_bz2
Summary: Imlib2 .bz2 loader
Group: System Environment/Libraries
%description loader_bz2
Bzip2 compressed image loader/saver for Imlib2
%package loader_gz
Summary: Imlib2 .gz loader
Group: System Environment/Libraries
%description loader_gz
gz compressed image loader/saver for Imlib2
%prep
%setup -q
%build
%{configure} --prefix=%{_prefix}
%{__make} %{?_smp_mflags} %{?mflags}
%install
%{__make} %{?mflags_install} DESTDIR=$RPM_BUILD_ROOT install
%clean
test "x$RPM_BUILD_ROOT" != "x/" && rm -rf $RPM_BUILD_ROOT
%post
/sbin/ldconfig
%postun
/sbin/ldconfig
%files
%defattr(-, root, root)
%doc AUTHORS COPYING README ChangeLog doc/index.html doc/imlib2.gif doc/blank.gif
%{_libdir}/lib*.so.*
%{_bindir}/*
%files devel
%defattr(-, root, root, 0755)
%{_libdir}/libImlib2.so
%{_libdir}/*.a
%{_libdir}/*.la
%{_libdir}/pkgconfig/imlib2.pc
%{_includedir}/*
%files filters
%attr(755,root,root) %{_libdir}/imlib2/filters/*.so
%files loader_lbm
%attr(755,root,root) %{_libdir}/imlib2/loaders/lbm.so
%files loader_jpeg
%attr(755,root,root) %{_libdir}/imlib2/loaders/jpeg.so
%files loader_png
%attr(755,root,root) %{_libdir}/imlib2/loaders/png.so
%files loader_argb
%attr(755,root,root) %{_libdir}/imlib2/loaders/argb.so
%files loader_bmp
%attr(755,root,root) %{_libdir}/imlib2/loaders/bmp.so
%files loader_gif
%attr(755,root,root) %{_libdir}/imlib2/loaders/gif.so
%files loader_pnm
%attr(755,root,root) %{_libdir}/imlib2/loaders/pnm.so
%files loader_tga
%attr(755,root,root) %{_libdir}/imlib2/loaders/tga.so
%files loader_tiff
%attr(755,root,root) %{_libdir}/imlib2/loaders/tiff.so
%files loader_xpm
%attr(755,root,root) %{_libdir}/imlib2/loaders/xpm.so
%files loader_bz2
%attr(755,root,root) %{_libdir}/imlib2/loaders/bz2.so
%files loader_gz
%attr(755,root,root) %{_libdir}/imlib2/loaders/zlib.so
%changelog

14
m4/ac_expand_dir.m4 Normal file
View File

@ -0,0 +1,14 @@
dnl AC_EXPAND_DIR(VARNAME, DIR)
dnl expands occurrences of ${prefix} and ${exec_prefix} in the given DIR,
dnl and assigns the resulting string to VARNAME
dnl example: AC_DEFINE_DIR(DATADIR, "$datadir")
dnl by Alexandre Oliva <oliva@dcc.unicamp.br>
AC_DEFUN([AC_EXPAND_DIR], [
$1=$2
$1=`(
test "x$prefix" = xNONE && prefix="$ac_default_prefix"
test "x$exec_prefix" = xNONE && exec_prefix="${prefix}"
eval echo \""[$]$1"\"
)`
])

136
m4/ac_path_generic.m4 Normal file
View File

@ -0,0 +1,136 @@
dnl @synopsis AC_PATH_GENERIC(LIBRARY [, MINIMUM-VERSION [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
dnl
dnl Runs a LIBRARY-config script and defines LIBRARY_CFLAGS and LIBRARY_LIBS
dnl
dnl The script must support `--cflags' and `--libs' args.
dnl If MINIMUM-VERSION is specified, the script must also support the
dnl `--version' arg.
dnl If the `--with-library-[exec-]prefix' arguments to ./configure are given,
dnl it must also support `--prefix' and `--exec-prefix'.
dnl (In other words, it must be like gtk-config.)
dnl
dnl For example:
dnl
dnl AC_PATH_GENERIC(Foo, 1.0.0)
dnl
dnl would run `foo-config --version' and check that it is at least 1.0.0
dnl
dnl If so, the following would then be defined:
dnl
dnl FOO_CFLAGS to `foo-config --cflags`
dnl FOO_LIBS to `foo-config --libs`
dnl
dnl At present there is no support for additional "MODULES" (see AM_PATH_GTK)
dnl (shamelessly stolen from gtk.m4 and then hacked around a fair amount)
dnl
dnl @author Angus Lees <gusl@cse.unsw.edu.au>
AC_DEFUN([AC_PATH_GENERIC],
[dnl
dnl we're going to need uppercase, lowercase and user-friendly versions of the
dnl string `LIBRARY'
pushdef([UP], translit([$1], [a-z], [A-Z]))dnl
pushdef([DOWN], translit([$1], [A-Z], [a-z]))dnl
dnl
dnl Get the cflags and libraries from the LIBRARY-config script
dnl
AC_ARG_WITH(DOWN-prefix,[ --with-]DOWN[-prefix=PFX Prefix where $1 is installed (optional)],
DOWN[]_config_prefix="$withval", DOWN[]_config_prefix="")
AC_ARG_WITH(DOWN-exec-prefix,[ --with-]DOWN[-exec-prefix=PFX Exec prefix where $1 is installed (optional)],
DOWN[]_config_exec_prefix="$withval", DOWN[]_config_exec_prefix="")
if test x$DOWN[]_config_exec_prefix != x ; then
DOWN[]_config_args="$DOWN[]_config_args --exec-prefix=$DOWN[]_config_exec_prefix"
if test x${UP[]_CONFIG+set} != xset ; then
UP[]_CONFIG=$DOWN[]_config_exec_prefix/bin/DOWN-config
fi
fi
if test x$DOWN[]_config_prefix != x ; then
DOWN[]_config_args="$DOWN[]_config_args --prefix=$DOWN[]_config_prefix"
if test x${UP[]_CONFIG+set} != xset ; then
UP[]_CONFIG=$DOWN[]_config_prefix/bin/DOWN-config
fi
fi
AC_PATH_PROG(UP[]_CONFIG, DOWN-config, no)
ifelse([$2], ,
AC_MSG_CHECKING(for $1),
AC_MSG_CHECKING(for $1 - version >= $2)
)
no_[]DOWN=""
if test "$UP[]_CONFIG" = "no" ; then
no_[]DOWN=yes
else
UP[]_CFLAGS="`$UP[]_CONFIG $DOWN[]_config_args --cflags`"
UP[]_LIBS="`$UP[]_CONFIG $DOWN[]_config_args --libs`"
ifelse([$2], , ,[
DOWN[]_config_major_version=`$UP[]_CONFIG $DOWN[]_config_args \
--version | sed 's/[[^0-9]]*\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
DOWN[]_config_minor_version=`$UP[]_CONFIG $DOWN[]_config_args \
--version | sed 's/[[^0-9]]*\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
DOWN[]_config_micro_version=`$UP[]_CONFIG $DOWN[]_config_args \
--version | sed 's/[[^0-9]]*\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
DOWN[]_wanted_major_version="regexp($2, [\<\([0-9]*\)], [\1])"
DOWN[]_wanted_minor_version="regexp($2, [\<\([0-9]*\)\.\([0-9]*\)], [\2])"
DOWN[]_wanted_micro_version="regexp($2, [\<\([0-9]*\).\([0-9]*\).\([0-9]*\)], [\3])"
# Compare wanted version to what config script returned.
# If I knew what library was being run, i'd probably also compile
# a test program at this point (which also extracted and tested
# the version in some library-specific way)
if test "$DOWN[]_config_major_version" -lt \
"$DOWN[]_wanted_major_version" \
-o \( "$DOWN[]_config_major_version" -eq \
"$DOWN[]_wanted_major_version" \
-a "$DOWN[]_config_minor_version" -lt \
"$DOWN[]_wanted_minor_version" \) \
-o \( "$DOWN[]_config_major_version" -eq \
"$DOWN[]_wanted_major_version" \
-a "$DOWN[]_config_minor_version" -eq \
"$DOWN[]_wanted_minor_version" \
-a "$DOWN[]_config_micro_version" -lt \
"$DOWN[]_wanted_micro_version" \) ; then
# older version found
no_[]DOWN=yes
echo -n "*** An old version of $1 "
echo -n "($DOWN[]_config_major_version"
echo -n ".$DOWN[]_config_minor_version"
echo ".$DOWN[]_config_micro_version) was found."
echo -n "*** You need a version of $1 newer than "
echo -n "$DOWN[]_wanted_major_version"
echo -n ".$DOWN[]_wanted_minor_version"
echo ".$DOWN[]_wanted_micro_version."
echo "***"
echo "*** If you have already installed a sufficiently new version, this error"
echo "*** probably means that the wrong copy of the DOWN-config shell script is"
echo "*** being found. The easiest way to fix this is to remove the old version"
echo "*** of $1, but you can also set the UP[]_CONFIG environment to point to the"
echo "*** correct copy of DOWN-config. (In this case, you will have to"
echo "*** modify your LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf"
echo "*** so that the correct libraries are found at run-time)"
fi
])
fi
if test "x$no_[]DOWN" = x ; then
AC_MSG_RESULT(yes)
ifelse([$3], , :, [$3])
else
AC_MSG_RESULT(no)
if test "$UP[]_CONFIG" = "no" ; then
echo "*** The DOWN-config script installed by $1 could not be found"
echo "*** If $1 was installed in PREFIX, make sure PREFIX/bin is in"
echo "*** your path, or set the UP[]_CONFIG environment variable to the"
echo "*** full path to DOWN-config."
fi
UP[]_CFLAGS=""
UP[]_LIBS=""
ifelse([$4], , :, [$4])
fi
AC_SUBST(UP[]_CFLAGS)
AC_SUBST(UP[]_LIBS)
popdef([UP])
popdef([DOWN])
])

2
src/Makefile.am Normal file
View File

@ -0,0 +1,2 @@
MAINTAINERCLEANFILES = Makefile.in
SUBDIRS = lib bin modules

35
src/bin/Makefile.am Normal file
View File

@ -0,0 +1,35 @@
MAINTAINERCLEANFILES = Makefile.in
INCLUDES = \
-I../lib \
-I$(top_srcdir)/src/lib \
@my_includes@
if BUILD_X11
X_BASED_PROGS = imlib2_show imlib2_test imlib2_bumpmap imlib2_poly imlib2_colorspace imlib2_view
endif
bin_PROGRAMS = \
imlib2_conv \
$(X_BASED_PROGS)
imlib2_conv_SOURCES = imlib2_conv.c
imlib2_conv_LDADD = $(top_builddir)/src/lib/libImlib2.la
imlib2_show_SOURCES = imlib2_show.c
imlib2_show_LDADD = $(top_builddir)/src/lib/libImlib2.la
imlib2_test_SOURCES = imlib2_test.c
imlib2_test_LDADD = $(top_builddir)/src/lib/libImlib2.la
imlib2_bumpmap_SOURCES = imlib2_bumpmap.c
imlib2_bumpmap_LDADD = $(top_builddir)/src/lib/libImlib2.la
imlib2_poly_SOURCES = imlib2_poly.c
imlib2_poly_LDADD = $(top_builddir)/src/lib/libImlib2.la
imlib2_colorspace_SOURCES = imlib2_colorspace.c
imlib2_colorspace_LDADD = $(top_builddir)/src/lib/libImlib2.la
imlib2_view_SOURCES = imlib2_view.c
imlib2_view_LDADD = $(top_builddir)/src/lib/libImlib2.la

128
src/bin/imlib2_bumpmap.c Normal file
View File

@ -0,0 +1,128 @@
#include "config.h"
#include <X11/Xlib.h>
#include <X11/extensions/XShm.h>
#include <X11/Xutil.h>
#include <X11/extensions/shape.h>
#include <X11/Xatom.h>
#include <X11/Xos.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
/*
#include <sys/time.h>
#include "common.h"
#include "image.h"
#include "rend.h"
#include "rgba.h"
#include "ximage.h"
#include "color.h"
*/
#include "Imlib2.h"
Display *disp;
Window win;
Visual *vis;
Colormap cm;
int depth;
int
main(int argc, char **argv)
{
int i, j, w, h, x, y;
Imlib_Image im = NULL, im_bg = NULL;
XEvent ev;
/**
* Initialization according to options
*/
printf("Initialising\n");
/**
* First tests to determine which rendering task to perform
*/
disp = XOpenDisplay(NULL);
vis = DefaultVisual(disp, DefaultScreen(disp));
depth = DefaultDepth(disp, DefaultScreen(disp));
cm = DefaultColormap(disp, DefaultScreen(disp));
win =
XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0,
0);
XSelectInput(disp, win,
ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
PointerMotionMask | ExposureMask);
XMapWindow(disp, win);
/**
* Start rendering
*/
printf("Rendering\n");
imlib_context_set_display(disp);
imlib_context_set_visual(vis);
imlib_context_set_colormap(cm);
imlib_context_set_drawable(win);
imlib_context_set_dither(1);
imlib_context_set_blend(0);
imlib_context_set_color_modifier(NULL);
im_bg = imlib_load_image(PACKAGE_DATA_DIR"/data/images/imlib2.png");
im = imlib_load_image(PACKAGE_DATA_DIR"/data/images/imlib2.png");
imlib_context_set_image(im_bg);
w = imlib_image_get_width();
h = imlib_image_get_height();
printf("Resizing Window to %d by %d\n", w, h);
XResizeWindow(disp, win, w, h);
XSync(disp, False);
x = -9999;
y = -9999;
while (1)
{
Imlib_Image *temp, *temp2;
do
{
XNextEvent(disp, &ev);
switch (ev.type)
{
case Expose:
break;
case ButtonRelease:
exit(0);
break;
case MotionNotify:
x = ev.xmotion.x;
y = ev.xmotion.y;
default:
break;
}
}
while (XPending(disp));
imlib_context_set_blend(0);
imlib_context_set_image(im_bg);
temp = imlib_clone_image();
imlib_context_set_image(temp);
/* imlib_blend_image_onto_image(im_bg, 0,
* 0, 0, w, h,
* 0, 0, w, h);
* first = 0; */
imlib_apply_filter
("bump_map_point(x=[],y=[],map="PACKAGE_DATA_DIR"/data/images/imlib2.png);", &x, &y);
temp2 = im_bg;
im_bg = temp;
imlib_context_set_image(im_bg);
imlib_render_image_on_drawable(0, 0);
im_bg = temp2;
imlib_context_set_image(temp);
imlib_free_image();
}
return 0;
}

143
src/bin/imlib2_colorspace.c Normal file
View File

@ -0,0 +1,143 @@
#include "config.h"
#include <X11/Xlib.h>
#include <X11/extensions/XShm.h>
#include <X11/Xutil.h>
#include <X11/extensions/shape.h>
#include <X11/Xatom.h>
#include <X11/Xos.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include "Imlib2.h"
Display *disp;
Window win;
Visual *vis;
Colormap cm;
int depth;
int
main(int argc, char **argv)
{
int w, h, tw, th;
Imlib_Image im_bg = NULL;
XEvent ev;
KeySym keysym;
static char kbuf[20];
Imlib_Font font;
Imlib_Color_Range range;
/**
* First tests to determine which rendering task to perform
*/
disp = XOpenDisplay(NULL);
vis = DefaultVisual(disp, DefaultScreen(disp));
depth = DefaultDepth(disp, DefaultScreen(disp));
cm = DefaultColormap(disp, DefaultScreen(disp));
win =
XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0,
0);
XSelectInput(disp, win,
ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
PointerMotionMask | ExposureMask | KeyPressMask);
XMapWindow(disp, win);
/**
* Start rendering
*/
imlib_set_font_cache_size(512 * 1024);
imlib_add_path_to_font_path(PACKAGE_DATA_DIR"/data/fonts");
imlib_context_set_display(disp);
imlib_context_set_visual(vis);
imlib_context_set_colormap(cm);
imlib_context_set_drawable(win);
imlib_context_set_blend(0);
imlib_context_set_color_modifier(NULL);
imlib_context_set_blend(0);
im_bg = imlib_create_image(600, 400);
imlib_context_set_image(im_bg);
w = imlib_image_get_width();
h = imlib_image_get_height();
imlib_context_set_color(128, 128, 255, 255);
imlib_image_fill_rectangle(0, 0, w, h);
XResizeWindow(disp, win, w, h);
XSync(disp, False);
while (1)
{
do
{
XNextEvent(disp, &ev);
switch (ev.type)
{
case ButtonRelease:
exit(0);
break;
case KeyPress:
XLookupString(&ev.xkey, (char *)kbuf, sizeof(kbuf), &keysym,
NULL);
switch (*kbuf)
{
case 'q':
exit(0);
default:
break;
}
break;
default:
break;
}
}
while (XPending(disp));
imlib_context_set_image(im_bg);
imlib_context_set_color(128, 128, 255, 255);
imlib_image_fill_rectangle(0, 0, w, h);
imlib_context_set_color(0, 0, 0, 255);
imlib_image_draw_rectangle(20, 20, 560, 140);
imlib_image_draw_rectangle(20, 220, 560, 140);
font = imlib_load_font("notepad/15");
if (font)
{
char text[4096];
imlib_context_set_font(font);
imlib_context_set_color(0, 0, 0, 255);
sprintf(text, "RGBA range, 2 points, from red to magenta");
imlib_get_text_size(text, &tw, &th);
imlib_text_draw(300 - tw / 2, 180 - th / 2, text);
sprintf(text, "HSVA range, 2 points, from red to magenta");
imlib_get_text_size(text, &tw, &th);
imlib_text_draw(300 - tw / 2, 380 - th / 2, text);
imlib_free_font();
}
/* Draw rectangle w/ RGBA gradient */
range = imlib_create_color_range();
imlib_context_set_color_range(range);
imlib_context_set_color(255, 0, 0, 255);
imlib_add_color_to_color_range(0);
imlib_context_set_color(255, 0, 255, 255);
imlib_add_color_to_color_range(20);
imlib_image_fill_color_range_rectangle(21, 21, 558, 138, -90.0);
imlib_free_color_range();
/* Draw rectangle w/ HSVA gradient */
range = imlib_create_color_range();
imlib_context_set_color_range(range);
imlib_context_set_color_hsva(0, 1, 1, 255);
imlib_add_color_to_color_range(0);
imlib_context_set_color_hsva(300, 1, 1, 255);
imlib_add_color_to_color_range(20);
imlib_image_fill_hsva_color_range_rectangle(21, 221, 558, 138, -90.0);
imlib_free_color_range();
imlib_render_image_on_drawable(0, 0);
}
return 0;
}

92
src/bin/imlib2_conv.c Normal file
View File

@ -0,0 +1,92 @@
#include "config.h"
/* Convert images between formats, using Imlib2's API. Smart enough to know
* about edb files; defaults to jpg's.
*/
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define X_DISPLAY_MISSING
#include <Imlib2.h>
#define PROG_NAME "imconvert"
static void usage(int exit_status);
int
main(int argc, char **argv)
{
char *dot, *colon, *n, *oldn;
Imlib_Image im;
/* I'm just plain being lazy here.. get our basename. */
for (oldn = n = argv[0]; n; oldn = n)
n = strchr(++oldn, '/');
if (argc < 3 || !strcmp(argv[1], "-h"))
usage(-1);
if ((im = imlib_load_image(argv[1])) == NULL)
{
fprintf(stderr, PROG_NAME ": Error loading image: %s\n", argv[1]);
exit(-1);
}
/* we only care what format the export format is. */
imlib_context_set_image(im);
/* hopefully the last one will be the one we want.. */
dot = strrchr(argv[2], '.');
/* if there's a format, snarf it and set the format. */
if (dot && *(dot + 1))
{
colon = strrchr(++dot, ':');
/* if a db file with a key, export it to a db. */
if (colon && *(colon + 1))
{
*colon = 0;
/* beats having to look for strcasecmp() */
if (!strncmp(dot, "db", 2) || !strncmp(dot, "dB", 2) ||
!strncmp(dot, "DB", 2) || !strncmp(dot, "Db", 2))
{
imlib_image_set_format("db");
}
*colon = ':';
}
else
{
char *p, *q;
/* max length of 8 for format name. seems reasonable. */
q = p = malloc(8);
memset(p, 0, 8);
strncpy(p, dot, (strlen(dot) < 9) ? strlen(dot) : 8);
/* Imlib2 only recognizes lowercase formats. convert it. */
for (q[8] = 0; *q; q++)
*q = tolower(*q);
imlib_image_set_format(p);
free(p);
}
dot--;
}
else
imlib_image_set_format("jpg");
imlib_save_image(argv[2]);
return 0;
}
static void
usage(int exit_status)
{
fprintf(exit_status ? stderr : stdout,
PROG_NAME ": Convert images between formats (part of the "
"Imlib2 package)\n\n"
"Usage: " PROG_NAME " [ -h | <image1> <image2[.fmt]> ]\n"
" <fmt> defaults to jpg if not provided; images in "
"edb files are supported via\n"
" the file.db:/key/name convention.\n"
" -h shows this help.\n\n");
exit(exit_status);
}

127
src/bin/imlib2_poly.c Normal file
View File

@ -0,0 +1,127 @@
#include "config.h"
#include <X11/Xlib.h>
#include <X11/extensions/XShm.h>
#include <X11/Xutil.h>
#include <X11/extensions/shape.h>
#include <X11/Xatom.h>
#include <X11/Xos.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include "Imlib2.h"
Display *disp;
Window win;
Visual *vis;
Colormap cm;
int depth;
int
main(int argc, char **argv)
{
int w, h;
Imlib_Image im_bg = NULL;
XEvent ev;
KeySym keysym;
static char kbuf[20];
ImlibPolygon poly, poly1, poly2;
/**
* First tests to determine which rendering task to perform
*/
disp = XOpenDisplay(NULL);
vis = DefaultVisual(disp, DefaultScreen(disp));
depth = DefaultDepth(disp, DefaultScreen(disp));
cm = DefaultColormap(disp, DefaultScreen(disp));
win =
XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0,
0);
XSelectInput(disp, win,
ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
PointerMotionMask | ExposureMask | KeyPressMask);
XMapWindow(disp, win);
/**
* Start rendering
*/
imlib_context_set_display(disp);
imlib_context_set_visual(vis);
imlib_context_set_colormap(cm);
imlib_context_set_drawable(win);
imlib_context_set_blend(0);
imlib_context_set_color_modifier(NULL);
imlib_context_set_blend(0);
im_bg = imlib_create_image(400, 400);
imlib_context_set_image(im_bg);
w = imlib_image_get_width();
h = imlib_image_get_height();
imlib_context_set_color(0, 0, 0, 255);
imlib_image_fill_rectangle(0, 0, w, h);
XResizeWindow(disp, win, w, h);
XSync(disp, False);
poly = imlib_polygon_new();
imlib_polygon_add_point(poly, 20, 20);
imlib_polygon_add_point(poly, 70, 20);
imlib_polygon_add_point(poly, 70, 70);
imlib_polygon_add_point(poly, 20, 70);
poly1 = imlib_polygon_new();
imlib_polygon_add_point(poly1, 100, 20);
imlib_polygon_add_point(poly1, 190, 100);
imlib_polygon_add_point(poly1, 120, 70);
poly2 = imlib_polygon_new();
imlib_polygon_add_point(poly2, 290, 20);
imlib_polygon_add_point(poly2, 200, 100);
imlib_polygon_add_point(poly2, 270, 70);
while (1)
{
do
{
XNextEvent(disp, &ev);
switch (ev.type)
{
case ButtonRelease:
exit(0);
break;
case KeyPress:
XLookupString(&ev.xkey, (char *)kbuf, sizeof(kbuf), &keysym,
NULL);
switch (*kbuf)
{
case ' ':
imlib_context_set_anti_alias
(!imlib_context_get_anti_alias());
printf("AA is %s\n",
imlib_context_get_anti_alias()? "on" : "off");
break;
case 'q':
exit(0);
default:
break;
}
break;
default:
break;
}
}
while (XPending(disp));
imlib_context_set_image(im_bg);
imlib_context_set_color(0, 0, 0, 255);
imlib_image_fill_rectangle(0, 0, w, h);
imlib_context_set_color(255, 255, 255, 255);
imlib_image_fill_polygon(poly);
imlib_image_fill_polygon(poly1);
imlib_image_fill_polygon(poly2);
imlib_render_image_on_drawable(0, 0);
}
return 0;
}

1378
src/bin/imlib2_show.c Normal file

File diff suppressed because it is too large Load Diff

274
src/bin/imlib2_test.c Normal file
View File

@ -0,0 +1,274 @@
#include "config.h"
/* include X11 stuff */
#include <X11/Xlib.h>
/* include Imlib2 stuff */
#include <Imlib2.h>
/* sprintf include */
#include <stdio.h>
/* some globals for our window & X display */
Display *disp;
Window win;
Visual *vis;
Colormap cm;
int depth;
/* the program... */
int
main(int argc, char **argv)
{
/* events we get from X */
XEvent ev;
/* areas to update */
Imlib_Updates updates, current_update;
/* our virtual framebuffer image we draw into */
Imlib_Image buffer;
/* a font */
Imlib_Font font;
/* our color range */
Imlib_Color_Range range;
/* our mouse x, y coordinates */
int mouse_x = 0, mouse_y = 0;
/* connect to X */
disp = XOpenDisplay(NULL);
/* get default visual , colormap etc. you could ask imlib2 for what it */
/* thinks is the best, but this example is intended to be simple */
vis = DefaultVisual(disp, DefaultScreen(disp));
depth = DefaultDepth(disp, DefaultScreen(disp));
cm = DefaultColormap(disp, DefaultScreen(disp));
/* create a window 640x480 */
win = XCreateSimpleWindow(disp, DefaultRootWindow(disp),
0, 0, 640, 480, 0, 0, 0);
/* tell X what events we are interested in */
XSelectInput(disp, win, ButtonPressMask | ButtonReleaseMask |
PointerMotionMask | ExposureMask);
/* show the window */
XMapWindow(disp, win);
/* set our cache to 2 Mb so it doesnt have to go hit the disk as long as */
/* the images we use use less than 2Mb of RAM (that is uncompressed) */
imlib_set_cache_size(2048 * 1024);
/* set the font cache to 512Kb - again to avoid re-loading */
imlib_set_font_cache_size(512 * 1024);
/* add the ./ttfonts dir to our font path - you'll want a notepad.ttf */
/* in that dir for the text to display */
imlib_add_path_to_font_path(PACKAGE_DATA_DIR"/data/fonts");
/* set the maximum number of colors to allocate for 8bpp and less to 128 */
imlib_set_color_usage(128);
/* dither for depths < 24bpp */
imlib_context_set_dither(1);
/* set the display , visual, colormap and drawable we are using */
imlib_context_set_display(disp);
imlib_context_set_visual(vis);
imlib_context_set_colormap(cm);
imlib_context_set_drawable(win);
/* infinite event loop */
for (;;)
{
/* image variable */
Imlib_Image image;
/* width and height values */
int w, h, text_w, text_h;
/* init our updates to empty */
updates = imlib_updates_init();
/* while there are events form X - handle them */
do
{
XNextEvent(disp, &ev);
switch (ev.type)
{
case Expose:
/* window rectangle was exposed - add it to the list of */
/* rectangles we need to re-render */
updates = imlib_update_append_rect(updates,
ev.xexpose.x,
ev.xexpose.y,
ev.xexpose.width,
ev.xexpose.height);
break;
case ButtonPress:
/* if we click anywhere in the window, exit */
exit(0);
break;
case MotionNotify:
/* if the mouse moves - note it */
/* add a rectangle update for the new mouse position */
image = imlib_load_image(PACKAGE_DATA_DIR"/data/images/mush.png");
imlib_context_set_image(image);
w = imlib_image_get_width();
h = imlib_image_get_height();
imlib_context_set_image(image);
imlib_free_image();
/* the old position - so we wipe over where it used to be */
updates = imlib_update_append_rect(updates,
mouse_x - (w / 2),
mouse_y - (h / 2), w, h);
font = imlib_load_font("notepad/30");
if (font)
{
char text[4096];
imlib_context_set_font(font);
sprintf(text, "Mouse is at %i, %i", mouse_x, mouse_y);
imlib_get_text_size(text, &text_w, &text_h);
imlib_free_font();
updates = imlib_update_append_rect(updates,
320 - (text_w / 2),
240 - (text_h / 2),
text_w, text_h);
}
mouse_x = ev.xmotion.x;
mouse_y = ev.xmotion.y;
/* the new one */
updates = imlib_update_append_rect(updates,
mouse_x - (w / 2),
mouse_y - (h / 2), w, h);
font = imlib_load_font("notepad/30");
if (font)
{
char text[4096];
imlib_context_set_font(font);
sprintf(text, "Mouse is at %i, %i", mouse_x, mouse_y);
imlib_get_text_size(text, &text_w, &text_h);
imlib_free_font();
updates = imlib_update_append_rect(updates,
320 - (text_w / 2),
240 - (text_h / 2),
text_w, text_h);
}
default:
/* any other events - do nothing */
break;
}
}
while (XPending(disp));
/* no more events for now ? ok - idle time so lets draw stuff */
/* take all the little rectangles to redraw and merge them into */
/* something sane for rendering */
updates = imlib_updates_merge_for_rendering(updates, 640, 480);
for (current_update = updates;
current_update;
current_update = imlib_updates_get_next(current_update))
{
int up_x, up_y, up_w, up_h;
/* find out where the first update is */
imlib_updates_get_coordinates(current_update,
&up_x, &up_y, &up_w, &up_h);
/* create our buffer image for renderign this update */
buffer = imlib_create_image(up_w, up_h);
/* we can blend stuff now */
imlib_context_set_blend(1);
/* fill the window background */
/* load the background image - you'll need to have some images */
/* in ./test_images lying around for this to actually work */
image = imlib_load_image(PACKAGE_DATA_DIR"/data/images/bg.png");
/* we're working with this image now */
imlib_context_set_image(image);
/* get its size */
w = imlib_image_get_width();
h = imlib_image_get_height();
/* now we want to work with the buffer */
imlib_context_set_image(buffer);
/* if the iimage loaded */
if (image)
{
/* blend image onto the buffer and scale it to 640x480 */
imlib_blend_image_onto_image(image, 0,
0, 0, w, h,
-up_x, -up_y, 640, 480);
/* working with the loaded image */
imlib_context_set_image(image);
/* free it */
imlib_free_image();
}
/* draw an icon centered around the mouse position */
image = imlib_load_image(PACKAGE_DATA_DIR"/data/images/mush.png");
imlib_context_set_image(image);
w = imlib_image_get_width();
h = imlib_image_get_height();
imlib_context_set_image(buffer);
if (image)
{
imlib_blend_image_onto_image(image, 0,
0, 0, w, h,
mouse_x - (w / 2) - up_x,
mouse_y - (h / 2) - up_y, w, h);
imlib_context_set_image(image);
imlib_free_image();
}
/* draw a gradient on top of things at the top left of the window */
/* create a range */
range = imlib_create_color_range();
imlib_context_set_color_range(range);
/* add white opaque as the first color */
imlib_context_set_color(255, 255, 255, 255);
imlib_add_color_to_color_range(0);
/* add an orange color, semi-transparent 10 units from the first */
imlib_context_set_color(255, 200, 10, 100);
imlib_add_color_to_color_range(10);
/* add black, fully transparent at the end 20 units away */
imlib_context_set_color(0, 0, 0, 0);
imlib_add_color_to_color_range(20);
/* draw the range */
imlib_context_set_image(buffer);
imlib_image_fill_color_range_rectangle(-up_x, -up_y, 128, 128,
-45.0);
/* free it */
imlib_free_color_range();
/* draw text - centered with the current mouse x, y */
font = imlib_load_font("notepad/30");
if (font)
{
char text[4096];
/* set the current font */
imlib_context_set_font(font);
/* set the image */
imlib_context_set_image(buffer);
/* set the color (black) */
imlib_context_set_color(0, 0, 0, 255);
/* print text to display in the buffer */
sprintf(text, "Mouse is at %i, %i", mouse_x, mouse_y);
/* query the size it will be */
imlib_get_text_size(text, &text_w, &text_h);
/* draw it */
imlib_text_draw(320 - (text_w / 2) - up_x,
240 - (text_h / 2) - up_y, text);
/* free the font */
imlib_free_font();
}
/* dont blend the image onto the drawable - slower */
imlib_context_set_blend(0);
/* set the buffer image as our current image */
imlib_context_set_image(buffer);
/* render the image at 0, 0 */
imlib_render_image_on_drawable(up_x, up_y);
/* don't need that temproary buffer image anymore */
imlib_free_image();
}
/* if we had updates - free them */
if (updates)
imlib_updates_free(updates);
/* loop again waiting for events */
}
return 0;
}

346
src/bin/imlib2_view.c Normal file
View File

@ -0,0 +1,346 @@
#include "config.h"
#include <X11/Xlib.h>
#include <X11/extensions/XShm.h>
#include <X11/Xutil.h>
#include <X11/extensions/shape.h>
#include <X11/Xatom.h>
#include <X11/Xos.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include "Imlib2.h"
Display *disp;
Window win;
Pixmap pm = 0;
Visual *vis;
Colormap cm;
int depth;
int image_width = 0, image_height = 0;
Imlib_Image bg_im = NULL;
static int
progress(Imlib_Image im, char percent, int update_x, int update_y,
int update_w, int update_h);
static int
progress(Imlib_Image im, char percent, int update_x, int update_y,
int update_w, int update_h)
{
/* first time it's called */
imlib_context_set_drawable(pm);
imlib_context_set_anti_alias(0);
imlib_context_set_dither(0);
imlib_context_set_blend(0);
if (image_width == 0)
{
int x, y, onoff;
imlib_context_set_image(im);
image_width = imlib_image_get_width();
image_height = imlib_image_get_height();
if (pm)
XFreePixmap(disp, pm);
pm = XCreatePixmap(disp, win, image_width, image_height, depth);
imlib_context_set_drawable(pm);
if (bg_im)
{
imlib_context_set_image(bg_im);
imlib_free_image_and_decache();
}
bg_im = imlib_create_image(image_width, image_height);
imlib_context_set_image(bg_im);
for (y = 0; y < image_height; y += 8)
{
onoff = (y / 8) & 0x1;
for (x = 0; x < image_width; x += 8)
{
if (onoff)
imlib_context_set_color(144, 144, 144, 255);
else
imlib_context_set_color(100, 100, 100, 255);
imlib_image_fill_rectangle(x, y, 8, 8);
onoff++;
if (onoff == 2)
onoff = 0;
}
}
imlib_render_image_part_on_drawable_at_size(0, 0, image_width,
image_height, 0, 0,
image_width, image_height);
XSetWindowBackgroundPixmap(disp, win, pm);
XResizeWindow(disp, win, image_width, image_height);
XMapWindow(disp, win);
XSync(disp, False);
}
imlib_context_set_anti_alias(0);
imlib_context_set_dither(0);
imlib_context_set_blend(1);
imlib_blend_image_onto_image(im, 0,
update_x, update_y,
update_w, update_h,
update_x, update_y, update_w, update_h);
imlib_context_set_blend(0);
imlib_render_image_part_on_drawable_at_size(update_x, update_y,
update_w, update_h,
update_x, update_y,
update_w, update_h);
XSetWindowBackgroundPixmap(disp, win, pm);
XClearArea(disp, win, update_x, update_y, update_w, update_h, False);
XFlush(disp);
return 1;
}
int
main(int argc, char **argv)
{
Imlib_Image *im = NULL;
char *file = NULL;
int no = 1;
if (argc < 2)
return 1;
file = argv[no];
disp = XOpenDisplay(NULL);
vis = DefaultVisual(disp, DefaultScreen(disp));
depth = DefaultDepth(disp, DefaultScreen(disp));
cm = DefaultColormap(disp, DefaultScreen(disp));
win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 10, 10,
0, 0, 0);
XSelectInput(disp, win, ButtonPressMask | ButtonReleaseMask |
ButtonMotionMask | PointerMotionMask);
imlib_context_set_display(disp);
imlib_context_set_visual(vis);
imlib_context_set_colormap(cm);
imlib_context_set_progress_function(progress);
imlib_context_set_progress_granularity(10);
imlib_context_set_drawable(win);
im = imlib_load_image(file);
while (!im)
{
no++;
if (no == argc)
exit(0);
file = argv[no];
image_width = 0;
im = imlib_load_image(file);
imlib_context_set_image(im);
}
if (!im)
{
fprintf(stderr, "Image format not available\n");
exit(0);
}
for (;;)
{
int x, y, b, count, fdsize, xfd, timeout = 0;
XEvent ev;
static int zoom_mode = 0, zx, zy;
static double zoom = 1.0;
struct timeval tval;
fd_set fdset;
double t1;
XFlush(disp);
while (XPending(disp))
{
XNextEvent(disp, &ev);
switch (ev.type)
{
case ButtonPress:
b = ev.xbutton.button;
x = ev.xbutton.x;
y = ev.xbutton.y;
if (b == 3)
{
zoom_mode = 1;
zx = x;
zy = y;
imlib_context_set_drawable(pm);
imlib_context_set_image(bg_im);
imlib_context_set_anti_alias(0);
imlib_context_set_dither(0);
imlib_context_set_blend(0);
imlib_render_image_part_on_drawable_at_size
(0, 0, image_width, image_height,
0, 0, image_width, image_height);
XSetWindowBackgroundPixmap(disp, win, pm);
XClearWindow(disp, win);
}
break;
case ButtonRelease:
b = ev.xbutton.button;
x = ev.xbutton.x;
y = ev.xbutton.y;
if (b == 3)
zoom_mode = 0;
if (b == 1)
{
no++;
if (no == argc)
no = argc - 1;
file = argv[no];
image_width = 0;
zoom = 1.0;
zoom_mode = 0;
imlib_context_set_image(im);
imlib_free_image_and_decache();
im = imlib_load_image(file);
while (!im)
{
no++;
if (no == argc)
exit(0);
file = argv[no];
image_width = 0;
im = imlib_load_image(file);
}
imlib_context_set_image(im);
}
if (b == 2)
{
no--;
if (no == 0)
no = 1;
file = argv[no];
image_width = 0;
zoom = 1.0;
zoom_mode = 0;
imlib_context_set_image(im);
imlib_free_image_and_decache();
im = imlib_load_image(file);
while (!im)
{
no--;
if (no == 0)
no = 1;
file = argv[no];
image_width = 0;
im = imlib_load_image(file);
}
imlib_context_set_image(im);
}
break;
case MotionNotify:
while (XCheckTypedWindowEvent
(disp, win, MotionNotify, &ev));
x = ev.xmotion.x;
y = ev.xmotion.y;
if (zoom_mode)
{
int sx, sy, sw, sh, dx, dy, dw, dh;
zoom = ((double)x - (double)zx) / 32.0;
if (zoom < 0)
zoom = 1.0 + ((zoom * 32.0) / ((double)(zx + 1)));
else
zoom += 1.0;
if (zoom <= 0.0001)
zoom = 0.0001;
if (zoom > 1.0)
{
dx = 0;
dy = 0;
dw = image_width;
dh = image_height;
sx = zx - (zx / zoom);
sy = zy - (zy / zoom);
sw = image_width / zoom;
sh = image_height / zoom;
}
else
{
dx = zx - (zx * zoom);
dy = zy - (zy * zoom);
dw = image_width * zoom;
dh = image_height * zoom;
sx = 0;
sy = 0;
sw = image_width;
sh = image_height;
}
imlib_context_set_anti_alias(0);
imlib_context_set_dither(0);
imlib_context_set_blend(0);
imlib_context_set_image(bg_im);
imlib_render_image_part_on_drawable_at_size
(sx, sy, sw, sh, dx, dy, dw, dh);
XSetWindowBackgroundPixmap(disp, win, pm);
XClearWindow(disp, win);
XFlush(disp);
timeout = 1;
}
default:
break;
}
t1 = 0.2;
tval.tv_sec = (long)t1;
tval.tv_usec = (long)((t1 - ((double)tval.tv_sec)) * 1000000);
xfd = ConnectionNumber(disp);
fdsize = xfd + 1;
FD_ZERO(&fdset);
FD_SET(xfd, &fdset);
if (timeout)
count = select(fdsize, &fdset, NULL, NULL, &tval);
else
count = select(fdsize, &fdset, NULL, NULL, NULL);
if (count < 0)
{
if ((errno == ENOMEM) || (errno == EINVAL)
|| (errno == EBADF))
exit(1);
}
else
{
if ((count == 0) && (timeout))
{
int sx, sy, sw, sh, dx, dy, dw, dh;
if (zoom > 1.0)
{
dx = 0;
dy = 0;
dw = image_width;
dh = image_height;
sx = zx - (zx / zoom);
sy = zy - (zy / zoom);
sw = image_width / zoom;
sh = image_height / zoom;
}
else
{
dx = zx - (zx * zoom);
dy = zy - (zy * zoom);
dw = image_width * zoom;
dh = image_height * zoom;
sx = 0;
sy = 0;
sw = image_width;
sh = image_height;
}
imlib_context_set_anti_alias(1);
imlib_context_set_dither(1);
imlib_context_set_blend(0);
imlib_context_set_image(bg_im);
imlib_render_image_part_on_drawable_at_size
(sx, sy, sw, sh, dx, dy, dw, dh);
XSetWindowBackgroundPixmap(disp, win, pm);
XClearWindow(disp, win);
XFlush(disp);
timeout = 0;
}
}
}
}
return 0;
}

481
src/lib/Imlib2.h Normal file
View File

@ -0,0 +1,481 @@
#ifndef __IMLIB_API_H
# define __IMLIB_API_H 1
/* Data types to use */
# ifndef DATA64
# define DATA64 unsigned long long
# define DATA32 unsigned int
# define DATA16 unsigned short
# define DATA8 unsigned char
# endif
/* opaque data types */
typedef void *Imlib_Context;
typedef void *Imlib_Image;
typedef void *Imlib_Color_Modifier;
typedef void *Imlib_Updates;
typedef void *Imlib_Font;
typedef void *Imlib_Color_Range;
typedef void *Imlib_Filter;
typedef struct _imlib_border Imlib_Border;
typedef struct _imlib_color Imlib_Color;
typedef void *ImlibPolygon;
/* blending operations */
enum _imlib_operation
{
IMLIB_OP_COPY,
IMLIB_OP_ADD,
IMLIB_OP_SUBTRACT,
IMLIB_OP_RESHADE
};
enum _imlib_text_direction
{
IMLIB_TEXT_TO_RIGHT = 0,
IMLIB_TEXT_TO_LEFT = 1,
IMLIB_TEXT_TO_DOWN = 2,
IMLIB_TEXT_TO_UP = 3,
IMLIB_TEXT_TO_ANGLE = 4
};
enum _imlib_load_error
{
IMLIB_LOAD_ERROR_NONE,
IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST,
IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY,
IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ,
IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT,
IMLIB_LOAD_ERROR_PATH_TOO_LONG,
IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT,
IMLIB_LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY,
IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE,
IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS,
IMLIB_LOAD_ERROR_OUT_OF_MEMORY,
IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS,
IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_WRITE,
IMLIB_LOAD_ERROR_OUT_OF_DISK_SPACE,
IMLIB_LOAD_ERROR_UNKNOWN
};
/* Encodings known to Imlib2 (so far) */
enum _imlib_TTF_encoding
{
IMLIB_TTF_ENCODING_ISO_8859_1,
IMLIB_TTF_ENCODING_ISO_8859_2,
IMLIB_TTF_ENCODING_ISO_8859_3,
IMLIB_TTF_ENCODING_ISO_8859_4,
IMLIB_TTF_ENCODING_ISO_8859_5
};
typedef enum _imlib_operation Imlib_Operation;
typedef enum _imlib_load_error Imlib_Load_Error;
typedef enum _imlib_text_direction Imlib_Text_Direction;
typedef enum _imlib_TTF_encoding Imlib_TTF_Encoding;
struct _imlib_border
{
int left, right, top, bottom;
};
struct _imlib_color
{
int alpha, red, green, blue;
};
/* Progressive loading callbacks */
typedef int (*Imlib_Progress_Function) (Imlib_Image im, char percent,
int update_x, int update_y,
int update_w, int update_h);
typedef void (*Imlib_Data_Destructor_Function) (Imlib_Image im, void *data);
#ifdef __cplusplus
extern "C"
{
#endif
/* context handling */
Imlib_Context imlib_context_new(void);
void imlib_context_free(Imlib_Context context);
void imlib_context_push(Imlib_Context context);
void imlib_context_pop(void);
Imlib_Context imlib_context_get(void);
/* context setting */
#ifndef X_DISPLAY_MISSING
void imlib_context_set_display(Display * display);
void imlib_context_set_visual(Visual * visual);
void imlib_context_set_colormap(Colormap colormap);
void imlib_context_set_drawable(Drawable drawable);
void imlib_context_set_mask(Pixmap mask);
#endif
void imlib_context_set_dither_mask(char dither_mask);
void imlib_context_set_anti_alias(char anti_alias);
void imlib_context_set_dither(char dither);
void imlib_context_set_blend(char blend);
void imlib_context_set_color_modifier(Imlib_Color_Modifier color_modifier);
void imlib_context_set_operation(Imlib_Operation operation);
void imlib_context_set_font(Imlib_Font font);
void imlib_context_set_direction(Imlib_Text_Direction direction);
void imlib_context_set_angle(double angle);
void imlib_context_set_color(int red, int green, int blue, int alpha);
void imlib_context_set_color_hsva(float hue, float saturation, float value, int alpha);
void imlib_context_set_color_hlsa(float hue, float lightness, float saturation, int alpha);
void imlib_context_set_color_cmya(int cyan, int magenta, int yellow, int alpha);
void imlib_context_set_color_range(Imlib_Color_Range color_range);
void imlib_context_set_progress_function(Imlib_Progress_Function
progress_function);
void imlib_context_set_progress_granularity(char progress_granularity);
void imlib_context_set_image(Imlib_Image image);
void imlib_context_set_cliprect(int x, int y, int w, int h);
void imlib_context_set_TTF_encoding(Imlib_TTF_Encoding encoding);
/* context getting */
#ifndef X_DISPLAY_MISSING
Display *imlib_context_get_display(void);
Visual *imlib_context_get_visual(void);
Colormap imlib_context_get_colormap(void);
Drawable imlib_context_get_drawable(void);
Pixmap imlib_context_get_mask(void);
#endif
char imlib_context_get_dither_mask(void);
char imlib_context_get_anti_alias(void);
char imlib_context_get_dither(void);
char imlib_context_get_blend(void);
Imlib_Color_Modifier imlib_context_get_color_modifier(void);
Imlib_Operation imlib_context_get_operation(void);
Imlib_Font imlib_context_get_font(void);
double imlib_context_get_angle(void);
Imlib_Text_Direction imlib_context_get_direction(void);
void imlib_context_get_color(int *red, int *green, int *blue, int *alpha);
void imlib_context_get_color_hsva(float *hue, float *saturation, float *value, int *alpha);
void imlib_context_get_color_hlsa(float *hue, float *lightness, float *saturation, int *alpha);
void imlib_context_get_color_cmya(int *cyan, int *magenta, int *yellow, int *alpha);
Imlib_Color *imlib_context_get_imlib_color(void);
Imlib_Color_Range imlib_context_get_color_range(void);
Imlib_Progress_Function imlib_context_get_progress_function(void);
char imlib_context_get_progress_granularity(void);
Imlib_Image imlib_context_get_image(void);
void imlib_context_get_cliprect(int *x, int *y, int *w, int *h);
Imlib_TTF_Encoding imlib_context_get_TTF_encoding(void);
int imlib_get_cache_size(void);
void imlib_set_cache_size(int bytes);
int imlib_get_color_usage(void);
void imlib_set_color_usage(int max);
void imlib_flush_loaders(void);
#ifndef X_DISPLAY_MISSING
int imlib_get_visual_depth(Display * display, Visual * visual);
Visual *imlib_get_best_visual(Display * display, int screen,
int *depth_return);
#endif
Imlib_Image imlib_load_image(const char *file);
Imlib_Image imlib_load_image_immediately(const char *file);
Imlib_Image imlib_load_image_without_cache(const char *file);
Imlib_Image imlib_load_image_immediately_without_cache(const char *file);
Imlib_Image imlib_load_image_with_error_return(const char *file,
Imlib_Load_Error *
error_return);
void imlib_free_image(void);
void imlib_free_image_and_decache(void);
/* query/modify image parameters */
int imlib_image_get_width(void);
int imlib_image_get_height(void);
const char *imlib_image_get_filename(void);
DATA32 *imlib_image_get_data(void);
DATA32 *imlib_image_get_data_for_reading_only(void);
void imlib_image_put_back_data(DATA32 * data);
char imlib_image_has_alpha(void);
void imlib_image_set_changes_on_disk(void);
void imlib_image_get_border(Imlib_Border * border);
void imlib_image_set_border(Imlib_Border * border);
void imlib_image_set_format(const char *format);
void imlib_image_set_irrelevant_format(char irrelevant);
void imlib_image_set_irrelevant_border(char irrelevant);
void imlib_image_set_irrelevant_alpha(char irrelevant);
char *imlib_image_format(void);
void imlib_image_set_has_alpha(char has_alpha);
void imlib_image_query_pixel(int x, int y, Imlib_Color * color_return);
void imlib_image_query_pixel_hsva(int x, int y, float *hue, float *saturation, float *value, int *alpha);
void imlib_image_query_pixel_hlsa(int x, int y, float *hue, float *lightness, float *saturation, int *alpha);
void imlib_image_query_pixel_cmya(int x, int y, int *cyan, int *magenta, int *yellow, int *alpha);
/* rendering functions */
#ifndef X_DISPLAY_MISSING
void imlib_render_pixmaps_for_whole_image(Pixmap * pixmap_return,
Pixmap * mask_return);
void imlib_render_pixmaps_for_whole_image_at_size(Pixmap * pixmap_return,
Pixmap * mask_return,
int width, int height);
void imlib_free_pixmap_and_mask(Pixmap pixmap);
void imlib_render_image_on_drawable(int x, int y);
void imlib_render_image_on_drawable_at_size(int x, int y, int width,
int height);
void imlib_render_image_part_on_drawable_at_size(int source_x,
int source_y,
int source_width,
int source_height, int x,
int y, int width,
int height);
DATA32 imlib_render_get_pixel_color(void);
#endif
void imlib_blend_image_onto_image(Imlib_Image source_image,
char merge_alpha, int source_x,
int source_y, int source_width,
int source_height, int destination_x,
int destination_y, int destination_width,
int destination_height);
/* creation functions */
Imlib_Image imlib_create_image(int width, int height);
Imlib_Image imlib_create_image_using_data(int width, int height,
DATA32 * data);
Imlib_Image imlib_create_image_using_copied_data(int width, int height,
DATA32 * data);
#ifndef X_DISPLAY_MISSING
Imlib_Image imlib_create_image_from_drawable(Pixmap mask, int x, int y,
int width, int height,
char need_to_grab_x);
Imlib_Image imlib_create_image_from_ximage(XImage *image, XImage *mask, int x, int y,
int width, int height,
char need_to_grab_x);
Imlib_Image imlib_create_scaled_image_from_drawable(Pixmap mask,
int source_x,
int source_y,
int source_width,
int source_height,
int destination_width,
int destination_height,
char need_to_grab_x,
char
get_mask_from_shape);
char imlib_copy_drawable_to_image(Pixmap mask, int x, int y, int width,
int height, int destination_x,
int destination_y, char need_to_grab_x);
#endif
Imlib_Image imlib_clone_image(void);
Imlib_Image imlib_create_cropped_image(int x, int y, int width,
int height);
Imlib_Image imlib_create_cropped_scaled_image(int source_x, int source_y,
int source_width,
int source_height,
int destination_width,
int destination_height);
/* imlib updates. lists of rectangles for storing required update draws */
Imlib_Updates imlib_updates_clone(Imlib_Updates updates);
Imlib_Updates imlib_update_append_rect(Imlib_Updates updates, int x, int y,
int w, int h);
Imlib_Updates imlib_updates_merge(Imlib_Updates updates, int w, int h);
Imlib_Updates imlib_updates_merge_for_rendering(Imlib_Updates updates,
int w, int h);
void imlib_updates_free(Imlib_Updates updates);
Imlib_Updates imlib_updates_get_next(Imlib_Updates updates);
void imlib_updates_get_coordinates(Imlib_Updates updates, int *x_return,
int *y_return, int *width_return,
int *height_return);
void imlib_updates_set_coordinates(Imlib_Updates updates, int x, int y,
int width, int height);
void imlib_render_image_updates_on_drawable(Imlib_Updates updates, int x,
int y);
Imlib_Updates imlib_updates_init(void);
Imlib_Updates imlib_updates_append_updates(Imlib_Updates updates,
Imlib_Updates appended_updates);
/* image modification */
void imlib_image_flip_horizontal(void);
void imlib_image_flip_vertical(void);
void imlib_image_flip_diagonal(void);
void imlib_image_orientate(int orientation);
void imlib_image_blur(int radius);
void imlib_image_sharpen(int radius);
void imlib_image_tile_horizontal(void);
void imlib_image_tile_vertical(void);
void imlib_image_tile(void);
/* fonts and text */
Imlib_Font imlib_load_font(const char *font_name);
void imlib_free_font(void);
void imlib_text_draw(int x, int y, const char *text);
void imlib_text_draw_with_return_metrics(int x, int y, const char *text,
int *width_return,
int *height_return,
int *horizontal_advance_return,
int *vertical_advance_return);
void imlib_get_text_size(const char *text, int *width_return,
int *height_return);
void imlib_get_text_advance(const char *text,
int *horizontal_advance_return,
int *vertical_advance_return);
int imlib_get_text_inset(const char *text);
void imlib_add_path_to_font_path(const char *path);
void imlib_remove_path_from_font_path(const char *path);
char **imlib_list_font_path(int *number_return);
int imlib_text_get_index_and_location(const char *text, int x, int y,
int *char_x_return,
int *char_y_return,
int *char_width_return,
int *char_height_return);
void imlib_text_get_location_at_index(const char *text, int index,
int *char_x_return,
int *char_y_return,
int *char_width_return,
int *char_height_return);
char **imlib_list_fonts(int *number_return);
void imlib_free_font_list(char **font_list, int number);
int imlib_get_font_cache_size(void);
void imlib_set_font_cache_size(int bytes);
void imlib_flush_font_cache(void);
int imlib_get_font_ascent(void);
int imlib_get_font_descent(void);
int imlib_get_maximum_font_ascent(void);
int imlib_get_maximum_font_descent(void);
/* color modifiers */
Imlib_Color_Modifier imlib_create_color_modifier(void);
void imlib_free_color_modifier(void);
void imlib_modify_color_modifier_gamma(double gamma_value);
void imlib_modify_color_modifier_brightness(double brightness_value);
void imlib_modify_color_modifier_contrast(double contrast_value);
void imlib_set_color_modifier_tables(DATA8 * red_table,
DATA8 * green_table,
DATA8 * blue_table,
DATA8 * alpha_table);
void imlib_get_color_modifier_tables(DATA8 * red_table,
DATA8 * green_table,
DATA8 * blue_table,
DATA8 * alpha_table);
void imlib_reset_color_modifier(void);
void imlib_apply_color_modifier(void);
void imlib_apply_color_modifier_to_rectangle(int x, int y, int width,
int height);
/* drawing on images */
Imlib_Updates imlib_image_draw_pixel(int x, int y, char make_updates);
Imlib_Updates imlib_image_draw_line(int x1, int y1, int x2, int y2,
char make_updates);
int imlib_clip_line(int x0, int y0, int x1, int y1, int xmin, int xmax,
int ymin, int ymax, int *clip_x0, int *clip_y0,
int *clip_x1, int *clip_y1);
void imlib_image_draw_rectangle(int x, int y, int width, int height);
void imlib_image_fill_rectangle(int x, int y, int width, int height);
void imlib_image_copy_alpha_to_image(Imlib_Image image_source, int x,
int y);
void imlib_image_copy_alpha_rectangle_to_image(Imlib_Image image_source,
int x, int y, int width,
int height,
int destination_x,
int destination_y);
void imlib_image_scroll_rect(int x, int y, int width, int height,
int delta_x, int delta_y);
void imlib_image_copy_rect(int x, int y, int width, int height, int new_x,
int new_y);
/* polygons */
ImlibPolygon imlib_polygon_new(void);
void imlib_polygon_free(ImlibPolygon poly);
void imlib_polygon_add_point(ImlibPolygon poly, int x, int y);
void imlib_image_draw_polygon(ImlibPolygon poly, unsigned char closed);
void imlib_image_fill_polygon(ImlibPolygon poly);
void imlib_polygon_get_bounds(ImlibPolygon poly, int *px1, int *py1,
int *px2, int *py2);
unsigned char imlib_polygon_contains_point(ImlibPolygon poly, int x,
int y);
/* ellipses */
void imlib_image_draw_ellipse(int xc, int yc, int a, int b);
void imlib_image_fill_ellipse(int xc, int yc, int a, int b);
/* color ranges */
Imlib_Color_Range imlib_create_color_range(void);
void imlib_free_color_range(void);
void imlib_add_color_to_color_range(int distance_away);
void imlib_image_fill_color_range_rectangle(int x, int y, int width,
int height, double angle);
void imlib_image_fill_hsva_color_range_rectangle(int x, int y, int width,
int height, double angle);
/* image data */
void imlib_image_attach_data_value(const char *key, void *data, int value,
Imlib_Data_Destructor_Function
destructor_function);
void *imlib_image_get_attached_data(const char *key);
int imlib_image_get_attached_value(const char *key);
void imlib_image_remove_attached_data_value(const char *key);
void imlib_image_remove_and_free_attached_data_value(const char *key);
/* saving */
void imlib_save_image(const char *filename);
void imlib_save_image_with_error_return(const char *filename,
Imlib_Load_Error * error_return);
/* FIXME: */
/* need to add arbitary rotation routines */
/* rotation/skewing */
Imlib_Image imlib_create_rotated_image(double angle);
/* rotation from buffer to context (without copying)*/
void imlib_rotate_image_from_buffer(double angle,
Imlib_Image source_image);
void imlib_blend_image_onto_image_at_angle(Imlib_Image source_image,
char merge_alpha, int source_x,
int source_y, int source_width,
int source_height,
int destination_x,
int destination_y, int angle_x,
int angle_y);
void imlib_blend_image_onto_image_skewed(Imlib_Image source_image,
char merge_alpha, int source_x,
int source_y, int source_width,
int source_height,
int destination_x,
int destination_y, int h_angle_x,
int h_angle_y, int v_angle_x,
int v_angle_y);
#ifndef X_DISPLAY_MISSING
void imlib_render_image_on_drawable_skewed(int source_x, int source_y,
int source_width,
int source_height,
int destination_x,
int destination_y,
int h_angle_x, int h_angle_y,
int v_angle_x, int v_angle_y);
void imlib_render_image_on_drawable_at_angle(int source_x, int source_y,
int source_width,
int source_height,
int destination_x,
int destination_y,
int angle_x, int angle_y);
#endif
/* image filters */
void imlib_image_filter(void);
Imlib_Filter imlib_create_filter(int initsize);
void imlib_context_set_filter(Imlib_Filter filter);
Imlib_Filter imlib_context_get_filter(void);
void imlib_free_filter(void);
void imlib_filter_set(int xoff, int yoff, int a, int r, int g, int b);
void imlib_filter_set_alpha(int xoff, int yoff, int a, int r, int g,
int b);
void imlib_filter_set_red(int xoff, int yoff, int a, int r, int g, int b);
void imlib_filter_set_green(int xoff, int yoff, int a, int r, int g,
int b);
void imlib_filter_set_blue(int xoff, int yoff, int a, int r, int g, int b);
void imlib_filter_constants(int a, int r, int g, int b);
void imlib_filter_divisors(int a, int r, int g, int b);
void imlib_apply_filter(char *script, ...);
void imlib_image_clear(void);
void imlib_image_clear_color(int r, int g, int b, int a);
#ifdef __cplusplus
}
#endif
#endif

83
src/lib/Makefile.am Normal file
View File

@ -0,0 +1,83 @@
AUTOMAKE_OPTIONS = 1.4 foreign
MAINTAINERCLEANFILES = Makefile.in
INCLUDES = @my_includes@ -I. -I$(top_srcdir) -I$(top_builddir)
lib_LTLIBRARIES = libImlib2.la
include_HEADERS = Imlib2.h
libImlib2_la_SOURCES = \
api.c \
blend.c \
blend.h \
color.c \
color.h \
color_helpers.c \
color_helpers.h \
colormod.c \
colormod.h \
common.h \
context.c \
context.h \
draw.c \
draw.h \
dynamic_filters.c \
dynamic_filters.h \
ellipse.c \
file.c \
file.h \
filter.c \
filter.h \
font.h \
font_draw.c \
font_load.c \
font_main.c \
font_query.c \
format.c \
format.h \
grab.c \
grab.h \
grad.c \
grad.h \
image.c \
image.h \
line.c \
loaderpath.h \
polygon.c \
rectangle.c \
rend.c \
rend.h \
rgba.c \
rgba.h \
rgbadraw.c \
rgbadraw.h \
rotate.c \
rotate.h \
scale.c \
scale.h \
script.c \
script.h \
span.c \
span.h \
updates.c \
updates.h \
ximage.c \
ximage.h
MMX_SRCS = \
asm_blend.S \
asm_blend_cmod.S \
asm_rgba.S \
asm_rotate.S \
asm_scale.S
EXTRA_libImlib2_la_SOURCES = $(MMX_SRCS)
MMX_OBJS = $(MMX_SRCS:.S=.lo)
if BUILD_MMX
libImlib2_la_LIBADD = $(MMX_OBJS) @my_libs@
libImlib2_la_DEPENDENCIES = $(top_builddir)/config.h $(MMX_OBJS)
else
libImlib2_la_LIBADD = @my_libs@
libImlib2_la_DEPENDENCIES = $(top_builddir)/config.h
endif
libImlib2_la_LDFLAGS = $(LDFLAGS) -version-info 3:0:2

5455
src/lib/api.c Normal file

File diff suppressed because it is too large Load Diff

1059
src/lib/asm_blend.S Normal file

File diff suppressed because it is too large Load Diff

1604
src/lib/asm_blend_cmod.S Normal file

File diff suppressed because it is too large Load Diff

301
src/lib/asm_rgba.S Normal file
View File

@ -0,0 +1,301 @@
#include <config.h>
#ifdef __EMX__
/* Due to strange behaviour of as.exe we use this macros */
/* For all OS/2 coders - please use PGCC to compile this code */
#define PR_(foo) ___##foo
#define PT_(foo,func) ___##foo,##func
#define SIZE(sym) \
.___end_##sym:; \
.size ___##sym,.___end_##sym-___##sym; \
.align 8;
#else
#define PR_(foo) __##foo
#define PT_(foo,func) __##foo,##func
#define SIZE(sym) \
.__end_##sym:; \
.size __##sym,.__end_##sym-__##sym; \
.align 8;
#endif
#ifdef DO_MMX_ASM
/*\
|*| MMX assembly rgba rendering routines for Imlib2
|*| Written by Willem Monsuwe <willem@stack.nl>
|*|
|*| Special (hairy) constructs are only commented on first use.
\*/
/*\ All functions have the same calling convention:
|*| __imlib_mmx_rgbXXX(void *src, int sjmp, void *dst, int dw,
|*| int w, int h, int dx, int dy)
\*/
#define src 8(%ebp)
#define sjmp 12(%ebp)
#define dst 16(%ebp)
#define dw 20(%ebp)
#define w 24(%ebp)
#define h 28(%ebp)
#define dx 32(%ebp)
#define dy 36(%ebp)
.text
.align 8
.globl PR_(imlib_mmx_rgb565_fast)
.type PT_(imlib_mmx_rgb565_fast,@function)
.globl PR_(imlib_mmx_bgr565_fast)
.type PT_(imlib_mmx_bgr565_fast,@function)
.globl PR_(imlib_mmx_rgb555_fast)
.type PT_(imlib_mmx_rgb555_fast,@function)
.globl PR_(imlib_mmx_bgr555_fast)
.type PT_(imlib_mmx_bgr555_fast,@function)
.globl PR_(imlib_get_cpuid)
.type PT_(imlib_get_cpuid,@function)
/*\ Some useful masks \*/
m_rb: .long 0x00f800f8, 0x00f800f8
m_r: .long 0xf800f800, 0xf800f800
m_g6: .long 0x0000fc00, 0x0000fc00
m_g5: .long 0x0000f800, 0x0000f800
/*\ Multiply constants to fake two shifts at once \*/
mul_rgb565: .long 0x20000004, 0x20000004
mul_bgr565: .long 0x00042000, 0x00042000
mul_rgb555: .long 0x20000008, 0x20000008
mul_bgr555: .long 0x00082000, 0x00082000
/*\ Common code \*/
/*\ Save registers, load common parameters \*/
#define ENTER \
pushl %ebp; \
movl %esp, %ebp; \
pushl %ebx; \
pushl %ecx; \
pushl %edx; \
pushl %edi; \
pushl %esi; \
movl src, %esi; \
movl dst, %edi; \
movl w, %ebx; \
movl h, %edx; \
addl %ebx, sjmp
#define LOOP_START \
testl %edx, %edx; \
jz 4f; \
testl %ebx, %ebx; \
jz 4f; \
0: \
movl %ebx, %ecx
#define LOOP_END \
3: \
movl sjmp, %ecx; \
leal (%esi, %ecx, 4), %esi; \
addl dw, %edi; \
decl %edx; \
jnz 0b; \
4:
/*\ Unset MMX mode, reset registers, return \*/
#define LEAVE \
emms; \
popl %esi; \
popl %edi; \
popl %edx; \
popl %ecx; \
popl %ebx; \
movl %ebp, %esp; \
popl %ebp; \
ret
PR_(imlib_mmx_bgr565_fast):
movq mul_bgr565, %mm7 /*\ This constant is the only difference \*/
jmp .rgb565_fast_entry
SIZE(imlib_mmx_bgr565_fast)
PR_(imlib_mmx_rgb565_fast):
movq mul_rgb565, %mm7
.rgb565_fast_entry:
ENTER
movq m_rb, %mm5
movq m_g6, %mm6
LOOP_START
test $1, %ecx
jz 1f
decl %ecx
movd (%esi, %ecx, 4), %mm0
movq %mm0, %mm1
pand %mm5, %mm0
pand %mm6, %mm1
pmaddwd %mm7, %mm0
por %mm1, %mm0
psrad $5, %mm0
movd %mm0, %eax
movw %ax, (%edi, %ecx, 2)
jz 3f
1:
test $2, %ecx
jz 2f
subl $2, %ecx
movq (%esi, %ecx, 4), %mm0
movq %mm0, %mm1
pand %mm5, %mm0
pand %mm6, %mm1
pmaddwd %mm7, %mm0
por %mm1, %mm0
pslld $11, %mm0
psrad $16, %mm0
packssdw %mm0, %mm0
movd %mm0, (%edi, %ecx, 2)
jz 3f
2:
subl $4, %ecx
movq (%esi, %ecx, 4), %mm0
movq 8(%esi, %ecx, 4), %mm2
movq %mm0, %mm1 /*\ a r g b (2x) \*/
movq %mm2, %mm3
pand %mm5, %mm0 /*\ 0 rrrrr000 0 bbbbb000 (2 x) \*/
pand %mm5, %mm2
pand %mm6, %mm1 /*\ 0 0 gggggg00 00000000 (2 x) \*/
pand %mm6, %mm3
pmaddwd %mm7, %mm0 /*\ 0 000rrrrr 000000bb bbb00000 (2 x) \*/
pmaddwd %mm7, %mm2
por %mm1, %mm0 /*\ 0 000rrrrr ggggggbb bbb00000 (2 x) \*/
por %mm3, %mm2
pslld $11, %mm0 /*\ rrrrrggg gggbbbbb 0 0 (2 x) \*/
pslld $11, %mm2
psrad $16, %mm0 /*\ x x rrrrrggg gggbbbbb (2 x) \*/
psrad $16, %mm2
packssdw %mm2, %mm0 /*\ rrrrrggg gggbbbbb (4 x) \*/
movq %mm0, (%edi, %ecx, 2)
jnz 2b
LOOP_END
LEAVE
SIZE(imlib_mmx_rgb565_fast)
PR_(imlib_mmx_bgr555_fast):
movq mul_bgr555, %mm7 /*\ This constant is the only difference \*/
jmp .rgb555_fast_entry
SIZE(imlib_mmx_bgr555_fast)
PR_(imlib_mmx_rgb555_fast):
movq mul_rgb555, %mm7
.rgb555_fast_entry:
ENTER
movq m_rb, %mm5
movq m_g5, %mm6
LOOP_START
test $1, %ecx
jz 1f
decl %ecx
movd (%esi, %ecx, 4), %mm0
movq %mm0, %mm1
pand %mm5, %mm0
pand %mm6, %mm1
pmaddwd %mm7, %mm0
por %mm1, %mm0
psrad $5, %mm0
movd %mm0, %eax
movw %ax, (%edi, %ecx, 2)
jz 3f
1:
test $2, %ecx
jz 2f
subl $2, %ecx
movq (%esi, %ecx, 4), %mm0
movq %mm0, %mm1
pand %mm5, %mm0
pand %mm6, %mm1
pmaddwd %mm7, %mm0
por %mm1, %mm0
psrld $6, %mm0
packssdw %mm0, %mm0
movd %mm0, (%edi, %ecx, 2)
jz 3f
2:
subl $4, %ecx
movq (%esi, %ecx, 4), %mm0
movq 8(%esi, %ecx, 4), %mm2
movq %mm0, %mm1 /*\ a r g b (2x) \*/
movq %mm2, %mm3
pand %mm5, %mm0 /*\ 0 rrrrr000 0 bbbbb000 (2 x) \*/
pand %mm5, %mm2
pand %mm6, %mm1 /*\ 0 0 ggggg000 00000000 (2 x) \*/
pand %mm6, %mm3
pmaddwd %mm7, %mm0 /*\ 0 000rrrrr 00000bbb bb000000 (2 x) \*/
pmaddwd %mm7, %mm2
por %mm1, %mm0 /*\ 0 000rrrrr gggggbbb bb000000 (2 x) \*/
por %mm3, %mm2
psrld $6, %mm0 /*\ 0 0 0rrrrrgg gggbbbbb (2 x) \*/
psrld $6, %mm2
packssdw %mm2, %mm0 /*\ 0rrrrrgg gggbbbbb (4 x) \*/
movq %mm0, (%edi, %ecx, 2)
jnz 2b
LOOP_END
LEAVE
SIZE(imlib_mmx_rgb555_fast)
PR_(imlib_get_cpuid):
pushl %ebx
pushl %edx
pushf
popl %eax
movl %eax, %ebx
xorl $0x200000, %eax
pushl %eax
popf
pushf
popl %eax
xorl %ebx, %eax
andl $0x200000, %eax
jz 1f
xorl %eax, %eax
cpuid
testl %eax, %eax
jz 1f
movl $1, %eax
cpuid
and $0x00000f00, %eax
and $0xfffff0ff, %edx
orl %edx, %eax
1:
popl %edx
popl %ebx
ret
SIZE(imlib_get_cpuid)
#endif

469
src/lib/asm_rotate.S Normal file
View File

@ -0,0 +1,469 @@
#include <config.h>
#ifdef __EMX__
/* Due to strange behaviour of as.exe we use this macros */
/* For all OS/2 coders - please use PGCC to compile this code */
#define PR_(foo) ___##foo
#define PT_(foo,func) ___##foo,##func
#define SIZE(sym) \
.___end_##sym:; \
.size ___##sym,.___end_##sym-___##sym; \
.align 8;
#else
#define PR_(foo) __##foo
#define PT_(foo,func) __##foo,##func
#define SIZE(sym) \
.__end_##sym:; \
.size __##sym,.__end_##sym-__##sym; \
.align 8;
#endif
#ifdef DO_MMX_ASM
/*\
|*| MMX assembly rotation routine for Imlib2
|*| Written by Willem Monsuwe <willem@stack.nl>
\*/
.text
.align 8
.globl PR_(imlib_mmx_RotateAA)
.type PT_(imlib_mmx_RotateAA,@function)
/*\ Prototype: __imlib_mmx_RotateAA(DATA32 *src, DATA32 *dest, int sow, int sw,
|*| int sh, int dow, int dw, int dh, int x, int y,
|*| int dxh, int dyh, int dxv, int dyv)
\*/
#define src 8(%ebp)
#define dest 12(%ebp)
#define sow 16(%ebp)
#define sw 20(%ebp)
#define sh 24(%ebp)
#define dow 28(%ebp)
#define dw 32(%ebp)
#define dh 36(%ebp)
#define x 40(%ebp)
#define y 44(%ebp)
#define dxh 48(%ebp)
#define dyh 52(%ebp)
#define dxv 56(%ebp)
#define dyv 60(%ebp)
/*\ Local variables \*/
#define j -4(%ebp)
#define dly -8(%ebp)
#define dlx -12(%ebp)
#define sht -16(%ebp)
#define swt -20(%ebp)
#define m0fffh -24(%ebp)
#define m0fff -28(%ebp)
#define mulsow -32(%ebp)
PR_(imlib_mmx_RotateAA):
pushl %ebp
movl %esp, %ebp
subl $40, %esp
pushl %ebx
pushl %ecx
pushl %edx
pushl %edi
pushl %esi
/*\ Check (dw > 0) && (dh > 0) \*/
cmpl $0, dw
jle .rotate_leave
cmpl $0, dh
jle .rotate_leave
pxor %mm7, %mm7
movl sow, %eax
sall $16, %eax
orl $1, %eax
movl %eax, mulsow
movl $0x0fff, %eax
movl %eax, m0fff
movl %eax, m0fffh
/*\ mm6 = x, y \*/
movq x, %mm6
/*\ edi = dest + dw \*/
movl dest, %edi
movl dw, %eax
leal (%edi, %eax, 4), %edi
/*\ dlx = dxv - dw * dxh \*/
movl dw, %eax
imull dxh, %eax
negl %eax
addl dxv, %eax
movl %eax, dlx
/*\ dly = dyv - dw * dyh \*/
movl dw, %eax
imull dyh, %eax
negl %eax
addl dyv, %eax
movl %eax, dly
/*\ j = dh \*/
movl dh, %eax
movl %eax, j
/*\ Check if all coordinates will be inside the source \*/
/*\ x < sw \*/
movl sw, %edx
movl x, %ecx
cmpl %edx, %ecx
jae .rotate_outside
/*\ x + dxh * dw < sw \*/
movl dxh, %ebx
imull dw, %ebx
addl %ebx, %ecx
cmpl %edx, %ecx
jae .rotate_outside
/*\ x + dxh * dw + dxv * dh < sw \*/
movl dxv, %eax
imull dh, %eax
subl %eax, %ecx
cmpl %edx, %ecx
jae .rotate_outside
/*\ x + dxv * dh < sw \*/
subl %ebx, %ecx
cmpl %edx, %ecx
jae .rotate_outside
/*\ y < sh \*/
movl sh, %edx
movl y, %ecx
cmpl %edx, %ecx
jae .rotate_outside
/*\ y + dyh * dw < sh \*/
movl dyh, %ebx
imull dw, %ebx
addl %ebx, %ecx
cmpl %edx, %ecx
jae .rotate_outside
/*\ y + dyh * dw + dyv * dh < sh \*/
movl dyv, %eax
imull dh, %eax
addl %eax, %ecx
cmpl %edx, %ecx
jae .rotate_outside
/*\ y + dyv * dh < sh \*/
subl %ebx, %ecx
cmpl %edx, %ecx
jae .rotate_outside
.rotate_inside:
movl sow, %ebx
movl src, %edx
.inside_loop_y:
/*\ i = -dw \*/
movl dw, %ecx
negl %ecx
.inside_loop_x:
/*\ esi = src + x >> 12 + (y >> 12) * sow \*/
movq %mm6, %mm0
psrad $12, %mm0
packssdw %mm0, %mm0
pmaddwd mulsow, %mm0
movd %mm0, %eax
leal (%edx, %eax, 4), %esi
/*\ x and y \*/
movq %mm6, %mm0
pand m0fff, %mm0
movq %mm0, %mm1
/*\ mm0 = x & 0xfff \*/
punpcklwd %mm0, %mm0
punpckldq %mm0, %mm0
/*\ mm1 = y & 0xfff \*/
punpckhwd %mm1, %mm1
punpckldq %mm1, %mm1
/*\ Load and unpack four pixels in parralel
|*| %mm2 = ptr[0], %mm3 = ptr[1]
|*| %mm4 = ptr[sow], %mm5 = ptr[sow + 1]
\*/
movq (%esi), %mm2
movq (%esi, %ebx, 4), %mm4
movq %mm2, %mm3
movq %mm4, %mm5
punpcklbw %mm7, %mm2
punpcklbw %mm7, %mm4
punpckhbw %mm7, %mm3
punpckhbw %mm7, %mm5
/*\ X interpolation: r = l + (r - l) * xap \*/
psubw %mm2, %mm3
psubw %mm4, %mm5
psllw $4, %mm3
psllw $4, %mm5
pmulhw %mm0, %mm3
pmulhw %mm0, %mm5
paddw %mm2, %mm3
paddw %mm4, %mm5
/*\ Y interpolation: d = u + (d - u) * yap \*/
psubw %mm3, %mm5
psllw $4, %mm5
pmulhw %mm1, %mm5
paddw %mm3, %mm5
packuswb %mm5, %mm5
movd %mm5, (%edi, %ecx, 4)
paddd dxh, %mm6
incl %ecx
jnz .inside_loop_x
paddd dlx, %mm6
movl dow, %ecx
leal (%edi, %ecx, 4), %edi
decl j
jnz .inside_loop_y
jmp .rotate_leave
.rotate_outside:
movl sw, %eax
decl %eax
sall $12, %eax
movl %eax, swt
movl sh, %eax
decl %eax
sall $12, %eax
movl %eax, sht
movl sow, %ebx
movl src, %edx
.outside_loop_y:
/*\ i = -dw \*/
movl dw, %ecx
negl %ecx
.outside_loop_x:
/*\ esi = src + x >> 12 + (y >> 12) * sow \*/
movq %mm6, %mm0
psrad $12, %mm0
packssdw %mm0, %mm0
pmaddwd mulsow, %mm0
movd %mm0, %eax
leal (%edx, %eax, 4), %esi
/*\ x & 0xfff and y & 0xfff \*/
movq %mm6, %mm0
pand m0fff, %mm0
movq %mm0, %mm1
/*\ x < swt \*/
movq %mm6, %mm2
psrlq $32, %mm2
movd %mm6, %eax
cmpl swt, %eax
jae 2f
/*\ y < sht \*/
movd %mm2, %eax
cmpl sht, %eax
jae 1f
/*\ 1234 \*/
.interp_argb:
/*\ Unpack x and y \*/
punpcklwd %mm0, %mm0
punpckldq %mm0, %mm0
punpckhwd %mm1, %mm1
punpckldq %mm1, %mm1
/*\ Load and unpack four pixels in parralel
|*| %mm2 = ptr[0], %mm3 = ptr[1]
|*| %mm4 = ptr[sow], %mm5 = ptr[sow + 1]
\*/
movq (%esi), %mm2
movq (%esi, %ebx, 4), %mm4
movq %mm2, %mm3
movq %mm4, %mm5
punpcklbw %mm7, %mm2
punpcklbw %mm7, %mm4
punpckhbw %mm7, %mm3
punpckhbw %mm7, %mm5
/*\ X interpolation: r = l + (r - l) * xap \*/
psubw %mm2, %mm3
psubw %mm4, %mm5
psllw $4, %mm3
psllw $4, %mm5
pmulhw %mm0, %mm3
pmulhw %mm0, %mm5
paddw %mm2, %mm3
paddw %mm4, %mm5
/*\ Y interpolation: d = u + (d - u) * yap \*/
psubw %mm3, %mm5
psllw $4, %mm5
pmulhw %mm1, %mm5
paddw %mm3, %mm5
packuswb %mm5, %mm5
movd %mm5, (%edi, %ecx, 4)
jmp .outside_il_end
1:
/*\ (-y-1) < 4096 \*/
notl %eax
cmpl $4095, %eax
ja 1f
/*\ ..34 \*/
pxor m0fff, %mm1
movd (%esi, %ebx, 4), %mm2
movd 4(%esi, %ebx, 4), %mm4
.interp_rgb_a0:
/*\ Unpack x and y \*/
punpcklwd %mm0, %mm0
punpckldq %mm0, %mm0
punpckhwd %mm1, %mm1
/*\ Unpack two pixels \*/
punpcklbw %mm7, %mm2
punpcklbw %mm7, %mm4
/*\ Interpolate \*/
psubw %mm2, %mm4
psllw $4, %mm4
pmulhw %mm0, %mm4
paddw %mm2, %mm4
/*\ Separate out alpha, multiply with mm1, and subtract \*/
movq %mm4, %mm2
psllq $48, %mm1
psllw $4, %mm4
pmulhw %mm1, %mm4
psubw %mm4, %mm2
packuswb %mm2, %mm2
movd %mm2, (%edi, %ecx, 4)
jmp .outside_il_end
1:
/*\ (y - sht) < 4096 \*/
notl %eax
subl sht, %eax
cmpl $4095, %eax
ja .outside_il_0
/*\ 12.. \*/
movd (%esi), %mm2
movd 4(%esi), %mm4
jmp .interp_rgb_a0
2:
/*\ Switch x and y \*/
psrlq $32, %mm0
psllq $32, %mm1
/*\ -x-1 < 4096 \*/
notl %eax
cmpl $4095, %eax
ja 2f
pxor m0fff, %mm1
/*\ y < sht \*/
movd %mm2, %eax
cmpl sht, %eax
jae 1f
/*\ .2.4 \*/
movd 4(%esi), %mm2
movd 4(%esi, %ebx, 4), %mm4
jmp .interp_rgb_a0
1:
/*\ (-y-1) < 4096 \*/
notl %eax
cmpl $4095, %eax
ja 1f
/*\ ...4 \*/
movd 4(%esi, %ebx, 4), %mm2
.interp_a000:
/*\ Separate out alpha, multiply with mm0 and mm1 \*/
pxor m0fff, %mm1
punpcklbw %mm7, %mm2
movq %mm2, %mm3
psllq $2, %mm0
psrlq $30, %mm1
pmulhw %mm0, %mm1
pxor m0fff, %mm1
psllq $48, %mm1
psllw $4, %mm3
pmulhw %mm1, %mm3
psubw %mm3, %mm2
packuswb %mm2, %mm2
movd %mm2, (%edi, %ecx, 4)
jmp .outside_il_end
1:
/*\ (y - sht) < 4096 \*/
notl %eax
subl sht, %eax
cmpl $4095, %eax
ja .outside_il_0
/*\ .2.. \*/
pxor m0fff, %mm0
movd 4(%esi), %mm2
jmp .interp_a000
2:
/*\ (x - swt) < 4096 \*/
notl %eax
subl swt, %eax
cmpl $4095, %eax
ja .outside_il_0
/*\ y < sht \*/
movd %mm2, %eax
cmpl sht, %eax
jae 1f
/*\ 1.3. \*/
movd (%esi), %mm2
movd (%esi, %ebx, 4), %mm4
jmp .interp_rgb_a0
1:
/*\ (-y-1) < 4096 \*/
notl %eax
cmpl $4095, %eax
ja 1f
/*\ ..3. \*/
movd (%esi, %ebx, 4), %mm2
jmp .interp_a000
1:
/*\ (y - sht) < 4096 \*/
notl %eax
subl sht, %eax
cmpl $4095, %eax
ja .outside_il_0
/*\ 1... \*/
pxor m0fff, %mm0
movd (%esi), %mm2
jmp .interp_a000
.outside_il_0:
movl $0, %eax
movl %eax, (%edi, %ecx, 4)
.outside_il_end:
paddd dxh, %mm6
incl %ecx
jnz .outside_loop_x
paddd dlx, %mm6
movl dow, %ecx
leal (%edi, %ecx, 4), %edi
decl j
jnz .outside_loop_y
.rotate_leave:
emms
popl %esi
popl %edi
popl %edx
popl %ecx
popl %ebx
movl %ebp, %esp
popl %ebp
ret
SIZE(imlib_mmx_RotateAA)
#endif

809
src/lib/asm_scale.S Normal file
View File

@ -0,0 +1,809 @@
#include <config.h>
#ifdef __EMX__
/* Due to strange behaviour of as.exe we use this macros */
/* For all OS/2 coders - please use PGCC to compile this code */
#define PR_(foo) ___##foo
#define PT_(foo,func) ___##foo,##func
#define SIZE(sym) \
.___end_##sym:; \
.size ___##sym,.___end_##sym-___##sym; \
.align 8;
#else
#define PR_(foo) __##foo
#define PT_(foo,func) __##foo,##func
#define SIZE(sym) \
.__end_##sym:; \
.size __##sym,.__end_##sym-__##sym; \
.align 8;
#endif
#ifdef DO_MMX_ASM
/*\
|*| MMX assembly scaling routine for Imlib2
|*| Written by Willem Monsuwe <willem@stack.nl>
\*/
.text
.align 8
.globl PR_(imlib_Scale_mmx_AARGBA)
.type PT_(imlib_Scale_mmx_AARGBA,@function)
/*\ Prototype: __imlib_Scale_mmx_AARGBA(ImlibScaleInfo *isi, DATA32 *dest,
|*| int dxx, int dyy, int dx, int dy, int dw, int dh, int dow, int sow)
\*/
#define isi 8(%ebp)
#define dest 12(%ebp)
#define dxx 16(%ebp)
#define dyy 20(%ebp)
#define dx 24(%ebp)
#define dy 28(%ebp)
#define dw 32(%ebp)
#define dh 36(%ebp)
#define dow 40(%ebp)
#define sow 44(%ebp)
/*\ Local variables that didn't fit in registers \*/
#define y -4(%ebp)
#define yp -8(%ebp)
#define yap -12(%ebp)
#define xp -16(%ebp)
#define xap -20(%ebp)
#define Cx -24(%ebp)
#define Mx -28(%ebp)
#define Cy -32(%ebp)
#define My -36(%ebp)
#define sow_4 -40(%ebp)
/*\ When %edx points to ImlibScaleInfo, these are the members \*/
#define xpoints (%edx)
#define ypoints 4(%edx)
#define xapoints 8(%edx)
#define yapoints 12(%edx)
#define xup_yup 16(%edx)
PR_(imlib_Scale_mmx_AARGBA):
pushl %ebp
movl %esp, %ebp
subl $40, %esp
pushl %ebx
pushl %ecx
pushl %edx
pushl %edi
pushl %esi
movl isi, %edx
/*\ Check (dw > 0) && (dh > 0) \*/
cmpl $0, dw
jle .scale_leave
cmpl $0, dh
jle .scale_leave
/*\ X-based array pointers point to the end; we're looping up to 0 \*/
/*\ %edi = dest + dow * dy + dx + dw \*/
movl dow, %eax
imull dy, %eax
addl dx, %eax
addl dw, %eax
movl dest, %edi
leal (%edi, %eax, 4), %edi
/*\ xp = xpoints + dxx + dw \*/
movl dxx, %ebx
addl dw, %ebx
movl xpoints, %eax
leal (%eax, %ebx, 4), %eax
movl %eax, xp
/*\ xap = xapoints + dxx + dw \*/
movl xapoints, %eax
leal (%eax, %ebx, 4), %eax
movl %eax, xap
/*\ y = dh \*/
movl dh, %eax
movl %eax, y
/*\ yp = ypoints + dyy \*/
movl dyy, %ebx
movl ypoints, %eax
leal (%eax, %ebx, 4), %eax
movl %eax, yp
/*\ yap = yapoints + dyy \*/
movl yapoints, %eax
leal (%eax, %ebx, 4), %eax
movl %eax, yap
pxor %mm7, %mm7
/*\ Test xup bit \*/
movl xup_yup, %eax
sarl $1, %eax
jnc .scale_x_down
.scale_x_up:
/*\ Test yup bit \*/
sarl $1, %eax
jnc .scale_x_up_y_down
/*\ Scaling up both ways \*/
.scale_x_up_y_up:
movl sow, %ebx
.up_up_loop_y:
/*\ x = -dw \*/
movl dw, %ecx
negl %ecx
/*\ %eax = *yap << 4 \*/
movl yap, %eax
movl (%eax), %eax
sall $4, %eax
jz .up_up_yap_0
movd %eax, %mm1
punpcklwd %mm1, %mm1
punpckldq %mm1, %mm1
.up_up_loop1_x:
/*\ %esi = *yp + xp[x] \*/
movl yp, %eax
movl (%eax), %esi
movl xp, %eax
movl (%eax, %ecx, 4), %eax
leal (%esi, %eax, 4), %esi
/*\ %eax = xap[x] << 4 \*/
movl xap, %eax
movl (%eax, %ecx, 4), %eax
sall $4, %eax
jz .up_up_xap_0
/*\ %mm0 = xap[x] << 4 \*/
movd %eax, %mm0
punpcklwd %mm0, %mm0
punpckldq %mm0, %mm0
/*\ Load and unpack four pixels in parralel
|*| %mm2 = ptr[0], %mm3 = ptr[1]
|*| %mm4 = ptr[sow], %mm5 = ptr[sow + 1]
\*/
movq (%esi), %mm2
movq (%esi, %ebx, 4), %mm4
movq %mm2, %mm3
movq %mm4, %mm5
punpcklbw %mm7, %mm2
punpcklbw %mm7, %mm4
punpckhbw %mm7, %mm3
punpckhbw %mm7, %mm5
/*\ X interpolation: r = l + (r - l) * xap \*/
psubw %mm2, %mm3
psubw %mm4, %mm5
psllw $4, %mm3
psllw $4, %mm5
pmulhw %mm0, %mm3
pmulhw %mm0, %mm5
paddw %mm2, %mm3
paddw %mm4, %mm5
/*\ Now %mm3 = I(ptr[0], ptr[1]), %mm5 = I(ptr[sow], ptr[sow + 1]) \*/
jmp .up_up_common
.up_up_xap_0:
/*\ Load and unpack two pixels
|*| %mm3 = ptr[0], %mm5 = ptr[sow]
\*/
movd (%esi), %mm3
movd (%esi, %ebx, 4), %mm5
punpcklbw %mm7, %mm3
punpcklbw %mm7, %mm5
.up_up_common:
/*\ Y interpolation: d = u + (d - u) * yap \*/
psubw %mm3, %mm5
psllw $4, %mm5
pmulhw %mm1, %mm5
paddw %mm3, %mm5
packuswb %mm5, %mm5
movd %mm5, (%edi, %ecx, 4)
/*\ while (++x) \*/
incl %ecx
jnz .up_up_loop1_x
jmp .up_up_yap_end
.up_up_yap_0:
.up_up_loop2_x:
/*\ %esi = *yp + xp[x] \*/
movl yp, %eax
movl (%eax), %esi
movl xp, %eax
movl (%eax, %ecx, 4), %eax
leal (%esi, %eax, 4), %esi
/*\ %eax = xap[x] << 4 \*/
movl xap, %eax
movl (%eax, %ecx, 4), %eax
sall $4, %eax
jz .up_up_0
/*\ %mm0 = xap[x] << 4 \*/
movd %eax, %mm0
punpcklwd %mm0, %mm0
punpckldq %mm0, %mm0
/*\ Load and unpack two pixels in parralel
|*| %mm2 = ptr[0], %mm3 = ptr[1]
\*/
movq (%esi), %mm2
movq %mm2, %mm3
punpcklbw %mm7, %mm2
punpckhbw %mm7, %mm3
/*\ X interpolation: r = l + (r - l) * xap \*/
psubw %mm2, %mm3
psllw $4, %mm3
pmulhw %mm0, %mm3
paddw %mm2, %mm3
packuswb %mm3, %mm3
movd %mm3, (%edi, %ecx, 4)
jmp .up_up_1
.up_up_0:
/*\ dptr[x] = *sptr \*/
movl (%esi), %eax
movl %eax, (%edi, %ecx, 4)
.up_up_1:
incl %ecx
jnz .up_up_loop2_x
.up_up_yap_end:
/*\ dptr += dow \*/
movl dow, %eax
leal (%edi, %eax, 4), %edi
/*\ yap++; yp++ \*/
addl $4, yap
addl $4, yp
/*\ while (y--) \*/
decl y
jnz .up_up_loop_y
jmp .scale_leave
/*\ Scaling down vertically \*/
.scale_x_up_y_down:
/*\ sow_4 = sow * 4 \*/
movl sow, %eax
sall $2, %eax
movl %eax, sow_4
.up_down_loop_y:
/*\ Setup My and Cy \*/
movl yap, %eax
movzwl (%eax), %ebx
movl %ebx, My
movzwl 2(%eax), %eax
movl %eax, Cy
/*\ mm4 = Cy \*/
movd %eax, %mm4
punpcklwd %mm4, %mm4
punpckldq %mm4, %mm4
/*\ mm5 = My \*/
movd %ebx, %mm5
punpcklwd %mm5, %mm5
punpckldq %mm5, %mm5
/*\ x = -dw \*/
movl dw, %ecx
negl %ecx
.up_down_loop_x:
/*\ %esi = *yp + xp[x] \*/
movl yp, %eax
movl (%eax), %esi
movl xp, %eax
movl (%eax, %ecx, 4), %eax
leal (%esi, %eax, 4), %esi
movl %esi, %eax
/*\ v = (*p * My) >> 10 \*/
movd (%eax), %mm0
punpcklbw %mm7, %mm0
psllw $6, %mm0
pmulhw %mm5, %mm0
/*\ i = 0x4000 - My \*/
movl $0x4000, %ebx
subl My, %ebx
jbe 5f
jmp 2f
1:
/*\ p += sow; v += (*p * Cy) >> 10 \*/
addl sow_4, %eax
movd (%eax), %mm1
punpcklbw %mm7, %mm1
psllw $6, %mm1
pmulhw %mm4, %mm1
paddw %mm1, %mm0
/*\ i -= Cy; while (i > Cy) \*/
subl Cy, %ebx
2:
cmpl Cy, %ebx
jg 1b
/*\ mm6 = i \*/
movd %ebx, %mm6
punpcklwd %mm6, %mm6
punpckldq %mm6, %mm6
/*\ p += sow; v += (*p * i) >> 10 \*/
addl sow_4, %eax
movd (%eax), %mm1
punpcklbw %mm7, %mm1
psllw $6, %mm1
pmulhw %mm6, %mm1
paddw %mm1, %mm0
5:
/*\ %eax = xap[x] << 5 \*/
movl xap, %eax
movl (%eax, %ecx, 4), %eax
sall $5, %eax
jz 6f
/*\ mm3 = xap[x] << 5 \*/
movd %eax, %mm3
punpcklwd %mm3, %mm3
punpckldq %mm3, %mm3
/*\ p + 1 \*/
movl %esi, %eax
addl $4, %eax
/*\ vv = (*p * My) >> 10 \*/
movd (%eax), %mm2
punpcklbw %mm7, %mm2
psllw $6, %mm2
pmulhw %mm5, %mm2
/*\ i = 0x4000 - My \*/
movl $0x4000, %ebx
subl My, %ebx
jbe 5f
jmp 2f
1:
/*\ p += sow; vv += (*p * Cy) >> 10 \*/
addl sow_4, %eax
movd (%eax), %mm1
punpcklbw %mm7, %mm1
psllw $6, %mm1
pmulhw %mm4, %mm1
paddw %mm1, %mm2
/*\ i -= Cy; while (i > Cy) \*/
subl Cy, %ebx
2:
cmpl Cy, %ebx
jg 1b
/*\ p += sow; v += (*p * i) >> 10 \*/
addl sow_4, %eax
movd (%eax), %mm1
punpcklbw %mm7, %mm1
psllw $6, %mm1
pmulhw %mm6, %mm1
paddw %mm1, %mm2
5:
/*\ v = v + (vv - v) * xap \*/
psubw %mm0, %mm2
psllw $3, %mm2
pmulhw %mm3, %mm2
paddw %mm2, %mm0
6:
/*\ dest[x] = v >> 4 \*/
psrlw $4, %mm0
packuswb %mm0, %mm0
movd %mm0, (%edi, %ecx, 4)
/*\ while (++x) \*/
incl %ecx
jnz .up_down_loop_x
/*\ dptr += dow \*/
movl dow, %eax
leal (%edi, %eax, 4), %edi
/*\ yap++; yp++ \*/
addl $4, yap
addl $4, yp
/*\ while (y--) \*/
decl y
jnz .up_down_loop_y
jmp .scale_leave
.scale_x_down:
/*\ Test yup bit \*/
sarl $1, %eax
jnc .scale_x_down_y_down
/*\ Scaling down horizontally \*/
.scale_x_down_y_up:
/*\ sow_4 = sow * 4 \*/
movl sow, %eax
sall $2, %eax
movl %eax, sow_4
.down_up_loop_y:
/*\ %eax = *yap << 5 \*/
movl yap, %eax
movl (%eax), %eax
sall $5, %eax
/*\ mm3 = *yap << 5 \*/
movd %eax, %mm3
punpcklwd %mm3, %mm3
punpckldq %mm3, %mm3
/*\ x = -dw \*/
movl dw, %ecx
negl %ecx
.down_up_loop_x:
/*\ %esi = *yp + xp[x] \*/
movl yp, %eax
movl (%eax), %esi
movl xp, %eax
movl (%eax, %ecx, 4), %eax
leal (%esi, %eax, 4), %esi
/*\ Setup Mx and Cx \*/
movl xap, %eax
movzwl (%eax, %ecx, 4), %ebx
movl %ebx, Mx
movzwl 2(%eax, %ecx, 4), %eax
movl %eax, Cx
/*\ mm4 = Cx \*/
movd %eax, %mm4
punpcklwd %mm4, %mm4
punpckldq %mm4, %mm4
/*\ mm5 = Mx \*/
movd %ebx, %mm5
punpcklwd %mm5, %mm5
punpckldq %mm5, %mm5
movl %esi, %eax
/*\ v = (*p * Mx) >> 10 \*/
movd (%eax), %mm0
punpcklbw %mm7, %mm0
psllw $6, %mm0
pmulhw %mm5, %mm0
/*\ i = 0x4000 - Mx \*/
movl $0x4000, %ebx
subl Mx, %ebx
jbe 5f
jmp 2f
1:
/*\ p += sow; v += (*p * Cx) >> 10 \*/
addl $4, %eax
movd (%eax), %mm1
punpcklbw %mm7, %mm1
psllw $6, %mm1
pmulhw %mm4, %mm1
paddw %mm1, %mm0
/*\ i -= Cx; while (i > Cx) \*/
subl Cx, %ebx
2:
cmpl Cx, %ebx
jg 1b
/*\ mm6 = i \*/
movd %ebx, %mm6
punpcklwd %mm6, %mm6
punpckldq %mm6, %mm6
/*\ p += sow; v += (*p * i) >> 10 \*/
addl $4, %eax
movd (%eax), %mm1
punpcklbw %mm7, %mm1
psllw $6, %mm1
pmulhw %mm6, %mm1
paddw %mm1, %mm0
5:
movd %mm3, %eax
testl %eax, %eax
jz 6f
/*\ p + sow \*/
movl %esi, %eax
addl sow_4, %eax
/*\ vv = (*p * Mx) >> 10 \*/
movd (%eax), %mm2
punpcklbw %mm7, %mm2
psllw $6, %mm2
pmulhw %mm5, %mm2
/*\ i = 0x4000 - Mx \*/
movl $0x4000, %ebx
subl Mx, %ebx
jbe 5f
jmp 2f
1:
/*\ p += sow; vv += (*p * Cx) >> 10 \*/
addl $4, %eax
movd (%eax), %mm1
punpcklbw %mm7, %mm1
psllw $6, %mm1
pmulhw %mm4, %mm1
paddw %mm1, %mm2
/*\ i -= Cx; while (i > Cx) \*/
subl Cx, %ebx
2:
cmpl Cx, %ebx
jg 1b
/*\ p += sow; v += (*p * i) >> 10 \*/
addl $4, %eax
movd (%eax), %mm1
punpcklbw %mm7, %mm1
psllw $6, %mm1
pmulhw %mm6, %mm1
paddw %mm1, %mm2
5:
/*\ v = v + (vv - v) * yap \*/
psubw %mm0, %mm2
psllw $3, %mm2
pmulhw %mm3, %mm2
paddw %mm2, %mm0
6:
/*\ dest[x] = v >> 4 \*/
psrlw $4, %mm0
packuswb %mm0, %mm0
movd %mm0, (%edi, %ecx, 4)
/*\ while (++x) \*/
incl %ecx
jnz .down_up_loop_x
/*\ dptr += dow \*/
movl dow, %eax
leal (%edi, %eax, 4), %edi
/*\ yap++; yp++ \*/
addl $4, yap
addl $4, yp
/*\ while (y--) \*/
decl y
jnz .down_up_loop_y
jmp .scale_leave
/*\ Scaling down both ways \*/
.scale_x_down_y_down:
/*\ sow_4 = sow * 4 \*/
movl sow, %eax
sall $2, %eax
movl %eax, sow_4
.down_down_loop_y:
/*\ Setup My and Cy \*/
movl yap, %eax
movzwl (%eax), %ebx
movl %ebx, My
movzwl 2(%eax), %eax
movl %eax, Cy
/*\ x = -dw \*/
movl dw, %ecx
negl %ecx
.down_down_loop_x:
/*\ %esi = *yp + xp[x] \*/
movl yp, %eax
movl (%eax), %esi
movl xp, %eax
movl (%eax, %ecx, 4), %eax
leal (%esi, %eax, 4), %esi
/*\ Setup Mx and Cx \*/
movl xap, %eax
movzwl (%eax, %ecx, 4), %ebx
movl %ebx, Mx
movzwl 2(%eax, %ecx, 4), %eax
movl %eax, Cx
/*\ mm3 = Cx \*/
movd %eax, %mm3
punpcklwd %mm3, %mm3
punpckldq %mm3, %mm3
/*\ mm5 = Mx \*/
movd %ebx, %mm5
punpcklwd %mm5, %mm5
punpckldq %mm5, %mm5
/*\ p = sptr; v = (*p * Mx) >> 9 \*/
movl %esi, %eax
movd (%eax), %mm0
punpcklbw %mm7, %mm0
psllw $7, %mm0
pmulhw %mm5, %mm0
/*\ i = 0x4000 - Mx \*/
movl $0x4000, %ebx
subl Mx, %ebx
jbe 5f
jmp 2f
1:
/*\ v += (*++p * Cx) >> 9 \*/
addl $4, %eax
movd (%eax), %mm1
punpcklbw %mm7, %mm1
psllw $7, %mm1
pmulhw %mm3, %mm1
paddw %mm1, %mm0
/*\ i -= Cx; while (i > Cx) \*/
subl Cx, %ebx
2:
cmpl Cx, %ebx
jg 1b
/*\ mm6 = i \*/
movd %ebx, %mm6
punpcklwd %mm6, %mm6
punpckldq %mm6, %mm6
/*\ v += (*++p * i) >> 9 \*/
addl $4, %eax
movd (%eax), %mm1
punpcklbw %mm7, %mm1
psllw $7, %mm1
pmulhw %mm6, %mm1
paddw %mm1, %mm0
5:
/*\ v *= My \*/
movd My, %mm4
punpcklwd %mm4, %mm4
punpckldq %mm4, %mm4
psllw $2, %mm0
pmulhw %mm4, %mm0
/*\ j = 0x4000 - My \*/
movl $0x4000, %edx
subl My, %edx
jbe 6f
jmp 4f
3:
/*\ sptr += sow; p = sptr \*/
addl sow_4, %esi
movl %esi, %eax
/*\ vx = (*p * Mx) >> 9 \*/
movd (%eax), %mm1
punpcklbw %mm7, %mm1
psllw $7, %mm1
pmulhw %mm5, %mm1
/*\ i = 0x4000 - Mx \*/
movl $0x4000, %ebx
subl Mx, %ebx
jbe 5f
jmp 2f
1:
/*\ vx += (*++p * Cx) >> 9 \*/
addl $4, %eax
movd (%eax), %mm2
punpcklbw %mm7, %mm2
psllw $7, %mm2
pmulhw %mm3, %mm2
paddw %mm2, %mm1
/*\ i -= Cx; while (i > Cx) \*/
subl Cx, %ebx
2:
cmpl Cx, %ebx
jg 1b
/*\ vx += (*++p * i) >> 9 \*/
addl $4, %eax
movd (%eax), %mm2
punpcklbw %mm7, %mm2
psllw $7, %mm2
pmulhw %mm6, %mm2
paddw %mm2, %mm1
5:
/*\ v += (vx * Cy) >> 14 \*/
movd Cy, %mm4
punpcklwd %mm4, %mm4
punpckldq %mm4, %mm4
psllw $2, %mm1
pmulhw %mm4, %mm1
paddw %mm1, %mm0
/*\ j -= Cy; while (j > Cy) \*/
subl Cy, %edx
4:
cmpl Cy, %edx
jg 3b
/*\ sptr += sow; p = sptr \*/
addl sow_4, %esi
movl %esi, %eax
/*\ vx = (*p * Mx) >> 9 \*/
movd (%eax), %mm1
punpcklbw %mm7, %mm1
psllw $7, %mm1
pmulhw %mm5, %mm1
/*\ i = 0x4000 - Mx \*/
movl $0x4000, %ebx
subl Mx, %ebx
jbe 5f
jmp 2f
1:
/*\ vx += (*++p * Cx) >> 9 \*/
addl $4, %eax
movd (%eax), %mm2
punpcklbw %mm7, %mm2
psllw $7, %mm2
pmulhw %mm3, %mm2
paddw %mm2, %mm1
/*\ i -= Cx; while (i > Cx) \*/
subl Cx, %ebx
2:
cmpl Cx, %ebx
jg 1b
/*\ vx += (*++p * i) >> 9 \*/
addl $4, %eax
movd (%eax), %mm2
punpcklbw %mm7, %mm2
psllw $7, %mm2
pmulhw %mm6, %mm2
paddw %mm2, %mm1
5:
/*\ v += (vx * j) >> 14 \*/
movd %edx, %mm4
punpcklwd %mm4, %mm4
punpckldq %mm4, %mm4
psllw $2, %mm1
pmulhw %mm4, %mm1
paddw %mm1, %mm0
6:
/*\ dptr[x] = mm0 >> 5 \*/
psrlw $5, %mm0
packuswb %mm0, %mm0
movd %mm0, (%edi, %ecx, 4)
/*\ while (++x) \*/
incl %ecx
jnz .down_down_loop_x
/*\ dptr += dow \*/
movl dow, %eax
leal (%edi, %eax, 4), %edi
/*\ yap++; yp++ \*/
addl $4, yap
addl $4, yp
/*\ while (y--) \*/
decl y
jnz .down_down_loop_y
jmp .scale_leave
.scale_leave:
emms
popl %esi
popl %edi
popl %edx
popl %ecx
popl %ebx
movl %ebp, %esp
popl %ebp
ret
SIZE(imlib_Scale_mmx_AARGBA)
#endif

1820
src/lib/blend.c Normal file

File diff suppressed because it is too large Load Diff

556
src/lib/blend.h Normal file
View File

@ -0,0 +1,556 @@
#ifndef __BLEND
#define __BLEND 1
#ifndef WORDS_BIGENDIAN
#define A_VAL(p) ((DATA8 *)(p))[3]
#define R_VAL(p) ((DATA8 *)(p))[2]
#define G_VAL(p) ((DATA8 *)(p))[1]
#define B_VAL(p) ((DATA8 *)(p))[0]
#else
#define A_VAL(p) ((DATA8 *)(p))[0]
#define R_VAL(p) ((DATA8 *)(p))[1]
#define G_VAL(p) ((DATA8 *)(p))[2]
#define B_VAL(p) ((DATA8 *)(p))[3]
#endif
/* FIXME: endian dependant */
#define READ_RGB(p, r, g, b) \
(r) = R_VAL(p); \
(g) = G_VAL(p); \
(b) = B_VAL(p);
#define READ_ALPHA(p, a) \
(a) = A_VAL(p);
#define READ_RGBA(p, r, g, b, a) \
(r) = R_VAL(p); \
(g) = G_VAL(p); \
(b) = B_VAL(p); \
(a) = A_VAL(p);
#define WRITE_RGB(p, r, g, b) \
R_VAL(p) = (r); \
G_VAL(p) = (g); \
B_VAL(p) = (b);
#define WRITE_RGB_PRESERVE_ALPHA(p, r, g, b) \
WRITE_RGB(p, r, g, b)
#define WRITE_RGBA(p, r, g, b, a) \
R_VAL(p) = (r); \
G_VAL(p) = (g); \
B_VAL(p) = (b); \
A_VAL(p) = (a);
#define INTERSECTS(x, y, w, h, xx, yy, ww, hh) \
((x < (xx + ww)) && \
(y < (yy + hh)) && \
((x + w) > xx) && \
((y + h) > yy))
#define CLIP_TO(_x, _y, _w, _h, _cx, _cy, _cw, _ch) \
{ \
if (INTERSECTS(_x, _y, _w, _h, _cx, _cy, _cw, _ch)) \
{ \
if (_x < _cx) \
{ \
_w += _x - _cx; \
_x = _cx; \
if (_w < 0) _w = 0; \
} \
if ((_x + _w) > (_cx + _cw)) \
_w = _cx + _cw - _x; \
if (_y < _cy) \
{ \
_h += _y - _cy; \
_y = _cy; \
if (_h < 0) _h = 0; \
} \
if ((_y + _h) > (_cy + _ch)) \
_h = _cy + _ch - _y; \
} \
else \
{ \
_w = 0; _h = 0; \
} \
}
/*
* 1) Basic Saturation - 8 bit unsigned
*
* The add, subtract, and reshade operations generate new color values that may
* be out of range for an unsigned 8 bit quantity. Therefore, we will want to
* saturate the values into the range [0, 255]. Any value < 0 will become 0,
* and any value > 255 will become 255. Or simply:
*
* saturated = (value < 0) ? 0 : ((value > 255) ? 255 : value)
*
* Of course the above isn't the most efficient means of saturating. Sometimes
* due to the nature of a calculation, we know we only need to saturate from
* above (> 255) or just from below (< 0). Or simply:
*
* saturated = (value < 0) ? 0 : value
* saturated = (value > 255) ? 255 : value
*
* 2) Alternate Forms of Saturation
*
* The methods of saturation described above use testing/branching operations,
* which are not necessarily efficient on all platforms. There are other means
* of performing saturation using just simple arithmetic operations
* (+, -, >>, <<, ~). A discussion of these saturation techniques follows.
*
* A) Saturation in the range [0, 512), or "from above".
*
* Assuming we have an integral value in the range [0, 512), the following
* formula evaluates to either 0, or 255:
*
* (value & 255) - ((value & 256) >> 8)
*
* This is easy to show. Notice that if the value is in the range [0, 256)
* the 9th bit is 0, and we get (0 - 0), which is 0. And if the value is in
* the range [256, 512) the 9th bit is 1, and we get (256 - 1), which is 255.
*
* Now, using the above information and the fact that assigning an integer to
* an 8 bit unsigned value will truncate to the lower 8 bits of the integer,
* the following properly saturates:
*
* 8bit_value = value | (value & 256) - ((value & 256) >> 8)
*
* To prove this to yourself, just think about what the lower 8 bits look like
* in the ranges [0, 256) and [256, 512). In particular, notice that the value
* in the range [0, 256) are unchanged, and values in the range [256, 512)
* always give you 255. Just what we want!
*
* B) Saturation in the range (-256, 256), or "from below".
*
* Assuming we have an integral value in the range (-256, 256), the following
* formula evaluates to either 0, or -1:
*
* ~(value >> 8)
*
* Here's why. If the value is in the range [0, 256), then shifting right by
* 8 bits gives us all 0 bits, or 0. And thus inverting the bits gives all
* 1 bits, which is -1. If the value is in the range (-256, 0), then the 9th
* bit and higher bits are all 1. So, when we shift right by 8 bits (with
* signed extension), we get a value with all 1 bits. Which when inverted is
* all 0 bits, or 0.
*
* Now, using the above information the following properly saturates:
*
* 8bit_value = value & (~(value >> 8))
*
* To prove this to yourself, noticed that values in the range (-256, 0) will
* always be AND'd with 0, and thus map to 0. Further, values in the range
* [0, 256) will always be AND'd with a value that is all 1 bits, and thus
* be unchanged. Just what we want!
*
* C) Saturation in the range (-256, 512), or "from above and below".
*
* The short of it is the following works:
*
* 8bit_value = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 9))
*
* We leave it to the reader to prove. Looks very similar to the techniques
* used above, eh? :)
*/
/* Saturate values in the range [0, 512) */
#define SATURATE_UPPER(nc, v) \
tmp = (v); \
nc = (tmp | (-(tmp >> 8)));
/* Saturate values in the range (-256, 256) */
#define SATURATE_LOWER(nc, v) \
tmp = (v); \
nc = tmp & (~(tmp >> 8));
/* Saturate values in the range (-256, 512) */
#define SATURATE_BOTH(nc, v) \
tmp = (v); \
nc = (tmp | (-(tmp >> 8))) & (~(tmp >> 9));
/*
* 1) Operations
*
* There are 4 operations supported:
*
* Copy, Add, Subtract, and Reshade
*
* For each operation there are 3 different variations that can be made:
*
* a) Use "blend" or "copy" in the calculations? A "blend" uses the alpha
* value of the source pixel to lighten the source pixel values. Where
* as "copy" ignores the alpha value and uses the raw source pixel values.
* b) Include source alpha in the calculation for new destination alpha?
* If source alpha is not used, then destination alpha is preserved.
* If source alpha is used, a "copy" sets the new alpha to the source
* alpha, and a "blend" increases it by a factor given by the product
* of the source alpha with one minus the destination alpha.
* c) Should the source pixels be passed through a color modifier before the
* calculations are performed?
*
* All together we have 4*2*2*2 = 32 combinations.
*
* 2) Copy operation
*
* The "copy" version of this operation copies the source image onto the
* destination image.
*
* The "blend" version of this operation blends the source image color 'c' with
* the destination image color 'cc' using 'a' (in the range [0, 1]) according
* to the following formula. Also notice that saturation is not needed for
* this calculation, the output is in the range [0, 255]:
*
* nc = c * alpha + (1 - alpha) * cc
* = c * alpha - cc * alpha + cc
* = (c - cc) * alpha + cc;
*
* A discussion of how we're calculating this value follows:
*
* We're using 'a', an integer, in the range [0, 255] for alpha (and for 'c'
* and 'cc', BTW). Therefore, we need to slightly modify the equation to take
* that into account. To get into the range [0, 255] we need to divide 'a'
* by 255:
*
* nc = ((c - cc) * a) / 255 + cc
*
* Notice that it is faster to divide by 256 (bit shifting), however without a
* fudge factor 'x' to balance things this isn't horribly accurate. So, let's
* solve for 'x'. The equality is:
*
* ((c - cc) * a) / 256 + cc + x = ((c - cc) * a) / 255 + cc
*
* The 'cc' terms cancel, and multiply both sides by 255*256 to remove the
* fractions:
*
* ((c - cc) * a) * 255 + 255 * 256 * x = ((c - cc) * a) * 256
*
* Get the 'x' term alone:
*
* 255 * 256 * x = ((c - cc) * a)
*
* Divide both sides by 255 * 256 to solve for 'x':
*
* x = ((c - cc) * a) / (255 * 256)
*
* And putting 'x' back into the equation we get:
*
* nc = ((c - cc) * a) / 256 + cc + ((c - cc) * a) / (255 * 256)
*
* And if we let 'tmp' represent the value '(c - cc) * a', and do a little
* regrouping we get:
*
* nc = tmp / 256 + tmp / (255 * 256) + cc
* = (tmp + tmp / 255) / 256 + cc
*
* We'll be using integer arithmetic, and over the range of values tmp takes
* (in [-255*255, 255*255]) the term tmp/(255*256) is pretty much the same as
* tmp/(256*256). So we get:
*
* nc = (tmp + tmp / 256) / 256 + cc
*
* And because the division of the sum uses integer arithmetic, it always
* rounds up/down even if that isn't the "best" choice. If we add .5 to the
* sum, we can get standard rounding: Like so:
*
* nc = (tmp + tmp / 256 + 128) / 256 + cc
*
* 3) Add operation
*
* The "copy" version of this operation sums the source image pixel values
* with the destination image pixel values, saturating at 255 (from above).
*
* The "blend" version of this operation sums the source image pixel values,
* after taking into account alpha transparency (e.g. a percentage), with the
* destination image pixel values, saturating at 255 (from above).
*
* 4) Subtract operation
*
* This operation is the same as the Add operation, except the source values
* are subtracted from the destination values (instead of added). Further,
* the result must be saturated at 0 (from below).
*
* 5) Reshade operation
*
* This operation uses the source image color values to lighten/darken color
* values in the destination image using the following formula:
*
* nc = cc + ((c - middle_value) * 2 * alpha)
*
* Recall our pixel color and alpha values are in the range [0, 255]. So, the
* "blend" version of this operation can be calculated as:
*
* nc = cc + ((c - 127) * 2 * (a / 255))
*
* And in an integer arithmetic friendly form is:
*
* nc = cc + (((c - 127) * a) >> 7)
*
* The "copy" version of this operation treats alpha as 1.0 (or a/255), and in
* integer arithmetic friendly form is:
*
* nc = cc + ((c - 127) << 1)
*
* Notice the color values created by this operation are in the range
* (-256, 512), and thus must be saturated at 0 and 255 (from above and below).
*
* For all the operations, when the "blend" version involves computing new
* destination alpha values via the use of some source alpha, we have that:
*
* nalpha = alpha + ((255 - alpha) * (a / 255))
*
* We can use the previous argument for approximating division by 255, and
* calculate this by:
*
* tmp = (255 - alpha) * a;
* nalpha = alpha + ((tmp + (tmp >> 8) + 0x80) >> 8);
*
* This is again in the range [0, 255], so no saturation is needed.
*/
#define BLEND_COLOR(a, nc, c, cc) \
tmp = ((c) - (cc)) * (a); \
nc = (cc) + ((tmp + (tmp >> 8) + 0x80) >> 8);
#define ADD_COLOR_WITH_ALPHA(a, nc, c, cc) \
tmp = (c) * (a); \
tmp = (cc) + ((tmp + (tmp >> 8) + 0x80) >> 8); \
nc = (tmp | (-(tmp >> 8)));
#define ADD_COLOR(nc, c, cc) \
tmp = (cc) + (c); \
nc = (tmp | (-(tmp >> 8)));
#define SUB_COLOR_WITH_ALPHA(a, nc, c, cc) \
tmp = (c) * (a); \
tmp = (cc) - ((tmp + (tmp >> 8) + 0x80) >> 8); \
nc = (tmp & (~(tmp >> 8)));
#define SUB_COLOR(nc, c, cc) \
tmp = (cc) - (c); \
nc = (tmp & (~(tmp >> 8)));
#define RESHADE_COLOR_WITH_ALPHA(a, nc, c, cc) \
tmp = (cc) + ((((c) - 127) * (a)) >> 7); \
nc = (tmp | (-(tmp >> 8))) & (~(tmp >> 9));
#define RESHADE_COLOR(nc, c, cc) \
tmp = (cc) + (((c) - 127) << 1); \
nc = (tmp | (-(tmp >> 8))) & (~(tmp >> 9));
extern int pow_lut_initialized;
extern DATA8 pow_lut[256][256];
#define BLEND_DST_ALPHA(r1, g1, b1, a1, dest) \
{ DATA8 _aa; \
_aa = pow_lut[a1][A_VAL(dest)]; \
BLEND_COLOR(a1, A_VAL(dest), 255, A_VAL(dest)); \
BLEND_COLOR(_aa, R_VAL(dest), r1, R_VAL(dest)); \
BLEND_COLOR(_aa, G_VAL(dest), g1, G_VAL(dest)); \
BLEND_COLOR(_aa, B_VAL(dest), b1, B_VAL(dest)); \
}
#define BLEND(r1, g1, b1, a1, dest) \
BLEND_COLOR(a1, R_VAL(dest), r1, R_VAL(dest)); \
BLEND_COLOR(a1, G_VAL(dest), g1, G_VAL(dest)); \
BLEND_COLOR(a1, B_VAL(dest), b1, B_VAL(dest));
#define BLEND_ADD(r1, g1, b1, a1, dest) \
ADD_COLOR_WITH_ALPHA(a1, R_VAL(dest), r1, R_VAL(dest)); \
ADD_COLOR_WITH_ALPHA(a1, G_VAL(dest), g1, G_VAL(dest)); \
ADD_COLOR_WITH_ALPHA(a1, B_VAL(dest), b1, B_VAL(dest));
#define BLEND_SUB(r1, g1, b1, a1, dest) \
SUB_COLOR_WITH_ALPHA(a1, R_VAL(dest), r1, R_VAL(dest)); \
SUB_COLOR_WITH_ALPHA(a1, G_VAL(dest), g1, G_VAL(dest)); \
SUB_COLOR_WITH_ALPHA(a1, B_VAL(dest), b1, B_VAL(dest));
#define BLEND_RE(r1, g1, b1, a1, dest) \
RESHADE_COLOR_WITH_ALPHA(a1, R_VAL(dest), r1, R_VAL(dest)); \
RESHADE_COLOR_WITH_ALPHA(a1, G_VAL(dest), g1, G_VAL(dest)); \
RESHADE_COLOR_WITH_ALPHA(a1, B_VAL(dest), b1, B_VAL(dest));
enum _imlibop
{
OP_COPY,
OP_ADD,
OP_SUBTRACT,
OP_RESHADE
};
typedef enum _imlibop ImlibOp;
typedef void (*ImlibBlendFunction)(DATA32*, int, DATA32*, int, int, int,
ImlibColorModifier *);
ImlibBlendFunction
__imlib_GetBlendFunction(ImlibOp op, char merge_alpha, char blend, char rgb_src,
ImlibColorModifier * cm);
void
__imlib_BlendImageToImage(ImlibImage *im_src, ImlibImage *im_dst,
char aa, char blend, char merge_alpha,
int ssx, int ssy, int ssw, int ssh,
int ddx, int ddy, int ddw, int ddh,
ImlibColorModifier *cm, ImlibOp op,
int clx, int cly, int clw, int clh);
void
__imlib_BlendRGBAToData(DATA32 *src, int src_w, int src_h, DATA32 *dst,
int dst_w, int dst_h, int sx, int sy, int dx, int dy,
int w, int h, char blend, char merge_alpha,
ImlibColorModifier *cm, ImlibOp op, char rgb_src);
void
__imlib_build_pow_lut(void);
#ifdef DO_MMX_ASM
void
__imlib_mmx_blend_rgba_to_rgb(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_blend_rgba_to_rgba(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_copy_rgba_to_rgb(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_copy_rgba_to_rgba(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_copy_rgb_to_rgba(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_add_blend_rgba_to_rgb(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_add_blend_rgba_to_rgba(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_add_copy_rgba_to_rgb(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_add_copy_rgba_to_rgba(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_add_copy_rgb_to_rgba(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_subtract_blend_rgba_to_rgb(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_subtract_blend_rgba_to_rgba(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_subtract_copy_rgba_to_rgb(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_subtract_copy_rgba_to_rgba(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_subtract_copy_rgb_to_rgba(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_reshade_blend_rgba_to_rgb(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_reshade_blend_rgba_to_rgba(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_reshade_copy_rgba_to_rgb(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_reshade_copy_rgba_to_rgba(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_reshade_copy_rgb_to_rgba(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_blend_rgba_to_rgb_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_blend_rgba_to_rgba_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_blend_rgb_to_rgb_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_blend_rgb_to_rgba_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_copy_rgba_to_rgb_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_copy_rgba_to_rgba_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_copy_rgb_to_rgba_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_add_blend_rgba_to_rgb_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_add_blend_rgba_to_rgba_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_add_blend_rgb_to_rgb_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_add_blend_rgb_to_rgba_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_add_copy_rgba_to_rgb_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_add_copy_rgba_to_rgba_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_add_copy_rgb_to_rgba_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_subtract_blend_rgba_to_rgb_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_subtract_blend_rgba_to_rgba_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_subtract_blend_rgb_to_rgb_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_subtract_blend_rgb_to_rgba_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_subtract_copy_rgba_to_rgb_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_subtract_copy_rgba_to_rgba_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_subtract_copy_rgb_to_rgba_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_reshade_blend_rgba_to_rgb_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_reshade_blend_rgba_to_rgba_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_reshade_blend_rgb_to_rgb_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_reshade_blend_rgb_to_rgba_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_reshade_copy_rgba_to_rgb_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_reshade_copy_rgba_to_rgba_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
void
__imlib_mmx_reshade_copy_rgb_to_rgba_cmod(DATA32 *src, int sw, DATA32 *dst,
int dw, int w, int h, ImlibColorModifier *cm);
#endif
#endif

573
src/lib/color.c Normal file
View File

@ -0,0 +1,573 @@
#include "common.h"
#ifdef BUILD_X11
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "color.h"
#endif
#ifdef BUILD_X11
DATA8 _pal_type = 0;
DATA16 _max_colors = 256;
int
__imlib_XActualDepth(Display * d, Visual * v)
{
XVisualInfo xvi, *xvir;
int depth = 0, num;
xvi.visual = v;
xvi.visualid = XVisualIDFromVisual(v);
xvir = XGetVisualInfo(d, VisualIDMask, &xvi, &num);
if (xvir)
{
depth = xvir[0].depth;
if ((depth == 16) &&
((xvir->red_mask | xvir->green_mask | xvir->blue_mask) == 0x7fff))
depth = 15;
XFree(xvir);
}
return depth;
}
Visual *
__imlib_BestVisual(Display * d, int screen, int *depth_return)
{
XVisualInfo xvi, *xvir;
int j, i, num, maxd = 0;
Visual *v = NULL;
const int visprefs[] =
{ PseudoColor, TrueColor, DirectColor, StaticColor, GrayScale,
StaticGray };
xvi.screen = screen;
maxd = 0;
for (j = 0; j < 6; j++)
{
xvi.class = visprefs[j];
xvir = XGetVisualInfo(d, VisualScreenMask | VisualClassMask,
&xvi, &num);
if (xvir)
{
for (i = 0; i < num; i++)
{
if ((xvir[i].depth > 1) &&
(xvir[i].depth >= maxd) && (xvi.class == PseudoColor))
{
maxd = xvir[i].depth;
v = xvir[i].visual;
}
else if ((xvir[i].depth > maxd) && (xvir[i].depth <= 24))
{
maxd = xvir[i].depth;
v = xvir[i].visual;
}
}
XFree(xvir);
}
}
if (depth_return)
*depth_return = maxd;
return v;
}
DATA8 *
__imlib_AllocColorTable(Display * d, Colormap cmap, DATA8 * type_return,
Visual * v)
{
DATA8 *color_lut = NULL;
if (v->bits_per_rgb > 1)
{
if ((_max_colors >= 256)
&& (color_lut = __imlib_AllocColors332(d, cmap, v)))
{
*type_return = _pal_type;
return color_lut;
}
if ((_max_colors >= 216)
&& (color_lut = __imlib_AllocColors666(d, cmap, v)))
{
*type_return = _pal_type;
return color_lut;
}
if ((_max_colors >= 128)
&& (color_lut = __imlib_AllocColors232(d, cmap, v)))
{
*type_return = _pal_type;
return color_lut;
}
if ((_max_colors >= 64)
&& (color_lut = __imlib_AllocColors222(d, cmap, v)))
{
*type_return = _pal_type;
return color_lut;
}
if ((_max_colors >= 32)
&& (color_lut = __imlib_AllocColors221(d, cmap, v)))
{
*type_return = _pal_type;
return color_lut;
}
if ((_max_colors >= 16)
&& (color_lut = __imlib_AllocColors121(d, cmap, v)))
{
*type_return = _pal_type;
return color_lut;
}
}
if ((_max_colors >= 8) && (color_lut = __imlib_AllocColors111(d, cmap, v)))
{
*type_return = _pal_type;
return color_lut;
}
color_lut = __imlib_AllocColors1(d, cmap, v);
*type_return = _pal_type;
return color_lut;
}
DATA8 *
__imlib_AllocColors332(Display * d, Colormap cmap, Visual * v)
{
int r, g, b, i;
DATA8 *color_lut;
int sig_mask = 0;
for (i = 0; i < v->bits_per_rgb; i++)
sig_mask |= (0x1 << i);
sig_mask <<= (16 - v->bits_per_rgb);
i = 0;
color_lut = malloc(256 * sizeof(DATA8));
for (r = 0; r < 8; r++)
{
for (g = 0; g < 8; g++)
{
for (b = 0; b < 4; b++)
{
XColor xcl;
XColor xcl_in;
int val;
Status ret;
val = (r << 6) | (r << 3) | (r);
xcl.red = (unsigned short)((val << 7) | (val >> 2));
val = (g << 6) | (g << 3) | (g);
xcl.green = (unsigned short)((val << 7) | (val >> 2));
val = (b << 6) | (b << 4) | (b << 2) | (b);
xcl.blue = (unsigned short)((val << 8) | (val));
xcl_in = xcl;
ret = XAllocColor(d, cmap, &xcl);
if ((ret == Success) ||
((xcl_in.red & sig_mask) != (xcl.red & sig_mask)) ||
((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) ||
((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask)))
{
unsigned long pixels[256];
int j;
if (i > 0)
{
for (j = 0; j < i; j++)
pixels[j] = (unsigned long)color_lut[j];
XFreeColors(d, cmap, pixels, i, 0);
}
free(color_lut);
return NULL;
}
color_lut[i] = xcl.pixel;
i++;
}
}
}
_pal_type = 0;
return color_lut;
}
DATA8 *
__imlib_AllocColors666(Display * d, Colormap cmap, Visual * v)
{
int r, g, b, i;
DATA8 *color_lut;
int sig_mask = 0;
for (i = 0; i < v->bits_per_rgb; i++)
sig_mask |= (0x1 << i);
sig_mask <<= (16 - v->bits_per_rgb);
i = 0;
color_lut = malloc(256 * sizeof(DATA8));
for (r = 0; r < 6; r++)
{
for (g = 0; g < 6; g++)
{
for (b = 0; b < 6; b++)
{
XColor xcl;
XColor xcl_in;
int val;
Status ret;
val = (int)((((double)r) / 5.0) * 65535);
xcl.red = (unsigned short)(val);
val = (int)((((double)g) / 5.0) * 65535);
xcl.green = (unsigned short)(val);
val = (int)((((double)b) / 5.0) * 65535);
xcl.blue = (unsigned short)(val);
xcl_in = xcl;
ret = XAllocColor(d, cmap, &xcl);
if ((ret == Success) ||
((xcl_in.red & sig_mask) != (xcl.red & sig_mask)) ||
((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) ||
((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask)))
{
unsigned long pixels[256];
int j;
if (i > 0)
{
for (j = 0; j < i; j++)
pixels[j] = (unsigned long)color_lut[j];
XFreeColors(d, cmap, pixels, i, 0);
}
free(color_lut);
return NULL;
}
color_lut[i] = xcl.pixel;
i++;
}
}
}
_pal_type = 7;
return color_lut;
}
DATA8 *
__imlib_AllocColors232(Display * d, Colormap cmap, Visual * v)
{
int r, g, b, i;
DATA8 *color_lut;
int sig_mask = 0;
for (i = 0; i < v->bits_per_rgb; i++)
sig_mask |= (0x1 << i);
sig_mask <<= (16 - v->bits_per_rgb);
i = 0;
color_lut = malloc(128 * sizeof(DATA8));
for (r = 0; r < 4; r++)
{
for (g = 0; g < 8; g++)
{
for (b = 0; b < 4; b++)
{
XColor xcl;
XColor xcl_in;
int val;
Status ret;
val = (r << 6) | (r << 4) | (r << 2) | (r);
xcl.red = (unsigned short)((val << 8) | (val));
val = (g << 6) | (g << 3) | (g);
xcl.green = (unsigned short)((val << 7) | (val >> 2));
val = (b << 6) | (b << 4) | (b << 2) | (b);
xcl.blue = (unsigned short)((val << 8) | (val));
xcl_in = xcl;
ret = XAllocColor(d, cmap, &xcl);
if ((ret == Success) ||
((xcl_in.red & sig_mask) != (xcl.red & sig_mask)) ||
((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) ||
((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask)))
{
unsigned long pixels[256];
int j;
if (i > 0)
{
for (j = 0; j < i; j++)
pixels[j] = (unsigned long)color_lut[j];
XFreeColors(d, cmap, pixels, i, 0);
}
free(color_lut);
return NULL;
}
color_lut[i] = xcl.pixel;
i++;
}
}
}
_pal_type = 1;
return color_lut;
}
DATA8 *
__imlib_AllocColors222(Display * d, Colormap cmap, Visual * v)
{
int r, g, b, i;
DATA8 *color_lut;
int sig_mask = 0;
for (i = 0; i < v->bits_per_rgb; i++)
sig_mask |= (0x1 << i);
sig_mask <<= (16 - v->bits_per_rgb);
i = 0;
color_lut = malloc(64 * sizeof(DATA8));
for (r = 0; r < 4; r++)
{
for (g = 0; g < 4; g++)
{
for (b = 0; b < 4; b++)
{
XColor xcl;
XColor xcl_in;
int val;
Status ret;
val = (r << 6) | (r << 4) | (r << 2) | (r);
xcl.red = (unsigned short)((val << 8) | (val));
val = (g << 6) | (g << 4) | (g << 2) | (g);
xcl.green = (unsigned short)((val << 8) | (val));
val = (b << 6) | (b << 4) | (b << 2) | (b);
xcl.blue = (unsigned short)((val << 8) | (val));
xcl_in = xcl;
ret = XAllocColor(d, cmap, &xcl);
if ((ret == Success) ||
((xcl_in.red & sig_mask) != (xcl.red & sig_mask)) ||
((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) ||
((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask)))
{
unsigned long pixels[256];
int j;
if (i > 0)
{
for (j = 0; j < i; j++)
pixels[j] = (unsigned long)color_lut[j];
XFreeColors(d, cmap, pixels, i, 0);
}
free(color_lut);
return NULL;
}
color_lut[i] = xcl.pixel;
i++;
}
}
}
_pal_type = 2;
return color_lut;
}
DATA8 *
__imlib_AllocColors221(Display * d, Colormap cmap, Visual * v)
{
int r, g, b, i;
DATA8 *color_lut;
int sig_mask = 0;
for (i = 0; i < v->bits_per_rgb; i++)
sig_mask |= (0x1 << i);
sig_mask <<= (16 - v->bits_per_rgb);
i = 0;
color_lut = malloc(32 * sizeof(DATA8));
for (r = 0; r < 4; r++)
{
for (g = 0; g < 4; g++)
{
for (b = 0; b < 2; b++)
{
XColor xcl;
XColor xcl_in;
int val;
Status ret;
val = (r << 6) | (r << 4) | (r << 2) | (r);
xcl.red = (unsigned short)((val << 8) | (val));
val = (g << 6) | (g << 4) | (g << 2) | (g);
xcl.green = (unsigned short)((val << 8) | (val));
val =
(b << 7) | (b << 6) | (b << 5) | (b << 4) | (b << 3) | (b
<<
2)
| (b << 1) | (b);
xcl.blue = (unsigned short)((val << 8) | (val));
xcl_in = xcl;
ret = XAllocColor(d, cmap, &xcl);
if ((ret == Success) ||
((xcl_in.red & sig_mask) != (xcl.red & sig_mask)) ||
((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) ||
((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask)))
{
unsigned long pixels[256];
int j;
if (i > 0)
{
for (j = 0; j < i; j++)
pixels[j] = (unsigned long)color_lut[j];
XFreeColors(d, cmap, pixels, i, 0);
}
free(color_lut);
return NULL;
}
color_lut[i] = xcl.pixel;
i++;
}
}
}
_pal_type = 3;
return color_lut;
}
DATA8 *
__imlib_AllocColors121(Display * d, Colormap cmap, Visual * v)
{
int r, g, b, i;
DATA8 *color_lut;
int sig_mask = 0;
for (i = 0; i < v->bits_per_rgb; i++)
sig_mask |= (0x1 << i);
sig_mask <<= (16 - v->bits_per_rgb);
i = 0;
color_lut = malloc(16 * sizeof(DATA8));
for (r = 0; r < 2; r++)
{
for (g = 0; g < 4; g++)
{
for (b = 0; b < 2; b++)
{
XColor xcl;
XColor xcl_in;
int val;
Status ret;
val =
(r << 7) | (r << 6) | (r << 5) | (r << 4) | (r << 3) | (r
<<
2)
| (r << 1) | (r);
xcl.red = (unsigned short)((val << 8) | (val));
val = (g << 6) | (g << 4) | (g << 2) | (g);
xcl.green = (unsigned short)((val << 8) | (val));
val =
(b << 7) | (b << 6) | (b << 5) | (b << 4) | (b << 3) | (b
<<
2)
| (b << 1) | (b);
xcl.blue = (unsigned short)((val << 8) | (val));
xcl_in = xcl;
ret = XAllocColor(d, cmap, &xcl);
if ((ret == Success) ||
((xcl_in.red & sig_mask) != (xcl.red & sig_mask)) ||
((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) ||
((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask)))
{
unsigned long pixels[256];
int j;
if (i > 0)
{
for (j = 0; j < i; j++)
pixels[j] = (unsigned long)color_lut[j];
XFreeColors(d, cmap, pixels, i, 0);
}
free(color_lut);
return NULL;
}
color_lut[i] = xcl.pixel;
i++;
}
}
}
_pal_type = 4;
return color_lut;
}
DATA8 *
__imlib_AllocColors111(Display * d, Colormap cmap, Visual * v)
{
int r, g, b, i;
DATA8 *color_lut;
int sig_mask = 0;
for (i = 0; i < v->bits_per_rgb; i++)
sig_mask |= (0x1 << i);
sig_mask <<= (16 - v->bits_per_rgb);
i = 0;
color_lut = malloc(8 * sizeof(DATA8));
for (r = 0; r < 2; r++)
{
for (g = 0; g < 2; g++)
{
for (b = 0; b < 2; b++)
{
XColor xcl;
XColor xcl_in;
int val;
Status ret;
val =
(r << 7) | (r << 6) | (r << 5) | (r << 4) | (r << 3) | (r
<<
2)
| (r << 1) | (r);
xcl.red = (unsigned short)((val << 8) | (val));
val =
(g << 7) | (g << 6) | (g << 5) | (g << 4) | (g << 3) | (g
<<
2)
| (g << 1) | (g);
xcl.green = (unsigned short)((val << 8) | (val));
val =
(b << 7) | (b << 6) | (b << 5) | (b << 4) | (b << 3) | (b
<<
2)
| (b << 1) | (b);
xcl.blue = (unsigned short)((val << 8) | (val));
xcl_in = xcl;
ret = XAllocColor(d, cmap, &xcl);
if ((ret == Success) ||
((xcl_in.red & sig_mask) != (xcl.red & sig_mask)) ||
((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) ||
((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask)))
{
unsigned long pixels[256];
int j;
if (i > 0)
{
for (j = 0; j < i; j++)
pixels[j] = (unsigned long)color_lut[j];
XFreeColors(d, cmap, pixels, i, 0);
}
free(color_lut);
return NULL;
}
color_lut[i] = xcl.pixel;
i++;
}
}
}
_pal_type = 5;
return color_lut;
}
DATA8 *
__imlib_AllocColors1(Display * d, Colormap cmap, Visual * v)
{
XColor xcl;
DATA8 *color_lut;
color_lut = malloc(2 * sizeof(DATA8));
xcl.red = (unsigned short)(0x0000);
xcl.green = (unsigned short)(0x0000);
xcl.blue = (unsigned short)(0x0000);
XAllocColor(d, cmap, &xcl);
color_lut[0] = xcl.pixel;
xcl.red = (unsigned short)(0xffff);
xcl.green = (unsigned short)(0xffff);
xcl.blue = (unsigned short)(0xffff);
XAllocColor(d, cmap, &xcl);
color_lut[1] = xcl.pixel;
_pal_type = 6;
return color_lut;
}
#endif

22
src/lib/color.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef __COLOR
#define __COLOR 1
#ifdef BUILD_X11
extern DATA16 _max_colors;
int __imlib_XActualDepth(Display *d, Visual *v);
Visual *__imlib_BestVisual(Display *d, int screen, int *depth_return);
DATA8 * __imlib_AllocColorTable(Display *d, Colormap cmap, DATA8 *type_return, Visual *v);
DATA8 * __imlib_AllocColors332(Display *d, Colormap cmap, Visual *v);
DATA8 * __imlib_AllocColors666(Display *d, Colormap cmap, Visual *v);
DATA8 * __imlib_AllocColors232(Display *d, Colormap cmap, Visual *v);
DATA8 * __imlib_AllocColors222(Display *d, Colormap cmap, Visual *v);
DATA8 * __imlib_AllocColors221(Display *d, Colormap cmap, Visual *v);
DATA8 * __imlib_AllocColors121(Display *d, Colormap cmap, Visual *v);
DATA8 * __imlib_AllocColors111(Display *d, Colormap cmap, Visual *v);
DATA8 * __imlib_AllocColors1(Display *d, Colormap cmap, Visual *v);
#endif
#endif

235
src/lib/color_helpers.c Normal file
View File

@ -0,0 +1,235 @@
#include "color_helpers.h"
/*
* Color space conversion helper routines
* Convert between rgb and hsv adn between rgb and hls
*/
void
__imlib_rgb_to_hsv(int r, int g, int b, float *hue, float *saturation,
float *value)
{
int f;
float i, j, k, max, min, d;
i = ((float)r) / 255.0;
j = ((float)g) / 255.0;
k = ((float)b) / 255.0;
f = 0;
max = min = i;
if (j > max)
{
max = j;
f = 1;
}
else
min = j;
if (k > max)
{
max = k;
f = 2;
}
else if (k < min)
min = k;
d = max - min;
*value = max;
if (max != 0)
*saturation = d / max;
else
*saturation = 0;
if (*saturation == 0)
*hue = 0;
else
{
switch (f)
{
case 0:
*hue = (j - k) / d;
break;
case 1:
*hue = 2 + (k - i) / d;
break;
case 2:
*hue = 4 + (i - j) / d;
break;
}
*hue *= 60.0;
if (*hue < 0)
*hue += 360.0;
}
}
void
__imlib_hsv_to_rgb(float hue, float saturation, float value, int *r, int *g,
int *b)
{
int i, p, q, t, h;
float vs, vsf;
i = (int)(value * 255.0);
if (saturation == 0)
*r = *g = *b = i;
else
{
if (hue == 360)
hue = 0;
hue = hue / 60.0;
h = (int)hue;
vs = value * saturation;
vsf = vs * (hue - h);
p = (int)(255.0 * (value - vs));
q = (int)(255.0 * (value - vsf));
t = (int)(255.0 * (value - vs + vsf));
switch (h)
{
case 0:
*r = i;
*g = t;
*b = p;
break;
case 1:
*r = q;
*g = i;
*b = p;
break;
case 2:
*r = p;
*g = i;
*b = t;
break;
case 3:
*r = p;
*g = q;
*b = i;
break;
case 4:
*r = t;
*g = p;
*b = i;
break;
case 5:
*r = i;
*g = p;
*b = q;
break;
}
}
}
void
__imlib_rgb_to_hls(int r, int g, int b, float *hue, float *lightness,
float *saturation)
{
int f;
float i, j, k, max, min, d;
i = ((float)r) / 255.0;
j = ((float)g) / 255.0;
k = ((float)b) / 255.0;
f = 0;
max = min = i;
if (j > max)
{
max = j;
f = 1;
}
else
min = j;
if (k > max)
{
max = k;
f = 2;
}
else if (k < min)
min = k;
d = max - min;
*lightness = (max + min) / 2.0;
if (d == 0)
{
*saturation = 0;
*hue = 0;
}
else
{
if (*lightness < 0.5)
*saturation = d / (max + min);
else
*saturation = d / (2 - max - min);
switch (f)
{
case 0:
*hue = (j - k) / d;
break;
case 1:
*hue = 2 + (k - i) / d;
break;
case 2:
*hue = 4 + (i - j) / d;
break;
}
*hue *= 60.0;
if (*hue < 0)
*hue += 360.0;
}
}
void
__imlib_hls_to_rgb(float hue, float lightness, float saturation, int *r, int *g,
int *b)
{
float m1, m2, m21, h;
if (saturation == 0)
*r = *g = *b = (int)(lightness * 255.0);
else
{
if (lightness <= 0.5)
m2 = lightness * (1 + saturation);
else
m2 = lightness + saturation + lightness * saturation;
m1 = 2 * lightness - m2;
m21 = m2 - m1;
h = hue + 120;
if (h > 360)
h -= 360;
else if (h < 0)
h += 360;
if (h < 60)
*r = (int)(255.0 * (m1 + m21 * h / 60.0));
else if (h < 180)
*r = (int)(255.0 * m2);
else if (h < 240)
*r = (int)(255.0 * (m1 + m21 * (240.0 - h) / 60.0));
else
*r = (int)(255.0 * m1);
h = hue;
if (h > 360)
h -= 360;
else if (h < 0)
h += 360;
if (h < 60)
*g = (int)(255.0 * (m1 + m21 * h / 60.0));
else if (h < 180)
*g = (int)(255.0 * m2);
else if (h < 240)
*g = (int)(255.0 * (m1 + m21 * (240.0 - h) / 60.0));
else
*g = (int)(255.0 * m1);
h = hue - 120;
if (h > 360)
h -= 360;
else if (h < 0)
h += 360;
if (h < 60)
*b = (int)(255.0 * (m1 + m21 * h / 60.0));
else if (h < 180)
*b = (int)(255.0 * m2);
else if (h < 240)
*b = (int)(255.0 * (m1 + m21 * (240.0 - h) / 60.0));
else
*b = (int)(255.0 * m1);
}
}

9
src/lib/color_helpers.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef __COLOR_HELPERS
#define __COLOR_HELPERS 1
void __imlib_rgb_to_hsv(int r, int g, int b, float *hue, float *saturation, float *value);
void __imlib_hsv_to_rgb(float hue, float saturation, float value, int *r, int *g, int *b);
void __imlib_rgb_to_hls(int r, int g, int b, float *hue, float *lightness, float *saturation);
void __imlib_hls_to_rgb(float hue, float lightness, float saturation, int *r, int *g, int *b);
#endif

254
src/lib/colormod.c Normal file
View File

@ -0,0 +1,254 @@
#include "common.h"
#include "colormod.h"
#include "file.h"
#include "loaderpath.h"
#include <math.h>
#include "image.h"
#include "blend.h"
static DATABIG mod_count = 0;
ImlibColorModifier *
__imlib_CreateCmod(void)
{
ImlibColorModifier *cm;
int i;
cm = malloc(sizeof(ImlibColorModifier));
cm->modification_count = mod_count;
for (i = 0; i < 256; i++)
{
cm->red_mapping[i] = (DATA8) i;
cm->green_mapping[i] = (DATA8) i;
cm->blue_mapping[i] = (DATA8) i;
cm->alpha_mapping[i] = (DATA8) i;
}
return cm;
}
void
__imlib_FreeCmod(ImlibColorModifier * cm)
{
free(cm);
}
void
__imlib_CmodChanged(ImlibColorModifier * cm)
{
mod_count++;
cm->modification_count = mod_count;
}
void
__imlib_CmodSetTables(ImlibColorModifier * cm,
DATA8 * r, DATA8 * g, DATA8 * b, DATA8 * a)
{
int i;
for (i = 0; i < 256; i++)
{
if (r)
cm->red_mapping[i] = r[i];
if (g)
cm->green_mapping[i] = g[i];
if (b)
cm->blue_mapping[i] = b[i];
if (a)
cm->alpha_mapping[i] = a[i];
}
__imlib_CmodChanged(cm);
}
void
__imlib_CmodReset(ImlibColorModifier * cm)
{
int i;
for (i = 0; i < 256; i++)
{
cm->red_mapping[i] = (DATA8) i;
cm->green_mapping[i] = (DATA8) i;
cm->blue_mapping[i] = (DATA8) i;
cm->alpha_mapping[i] = (DATA8) i;
}
__imlib_CmodChanged(cm);
}
void
__imlib_DataCmodApply(DATA32 * data, int w, int h, int jump,
ImlibImageFlags * fl, ImlibColorModifier * cm)
{
int x, y;
DATA32 *p;
/* We might be adding alpha */
if (fl && !(*fl & F_HAS_ALPHA))
{
p = data;
for (y = 0; y < h; y++)
{
for (x = 0; x < w; x++)
{
R_VAL(p) = R_CMOD(cm, R_VAL(p));
G_VAL(p) = G_CMOD(cm, G_VAL(p));
B_VAL(p) = B_CMOD(cm, B_VAL(p));
A_VAL(p) = A_CMOD(cm, 255);
p++;
}
p += jump;
}
if (A_CMOD(cm, 255) != 255)
*fl |= F_HAS_ALPHA;
return;
}
p = data;
for (y = 0; y < h; y++)
{
for (x = 0; x < w; x++)
{
R_VAL(p) = R_CMOD(cm, R_VAL(p));
G_VAL(p) = G_CMOD(cm, G_VAL(p));
B_VAL(p) = B_CMOD(cm, B_VAL(p));
A_VAL(p) = A_CMOD(cm, A_VAL(p));
p++;
}
p += jump;
}
}
void
__imlib_CmodGetTables(ImlibColorModifier * cm, DATA8 * r, DATA8 * g,
DATA8 * b, DATA8 * a)
{
if (r)
memcpy(r, cm->red_mapping, (256 * sizeof(DATA8)));
if (g)
memcpy(g, cm->green_mapping, (256 * sizeof(DATA8)));
if (b)
memcpy(b, cm->blue_mapping, (256 * sizeof(DATA8)));
if (a)
memcpy(a, cm->alpha_mapping, (256 * sizeof(DATA8)));
}
void
__imlib_CmodModBrightness(ImlibColorModifier * cm, double v)
{
int i, val, val2;
val = (int)(v * 255);
for (i = 0; i < 256; i++)
{
val2 = (int)cm->red_mapping[i] + val;
if (val2 < 0)
val2 = 0;
if (val2 > 255)
val2 = 255;
cm->red_mapping[i] = (DATA8) val2;
val2 = (int)cm->green_mapping[i] + val;
if (val2 < 0)
val2 = 0;
if (val2 > 255)
val2 = 255;
cm->green_mapping[i] = (DATA8) val2;
val2 = (int)cm->blue_mapping[i] + val;
if (val2 < 0)
val2 = 0;
if (val2 > 255)
val2 = 255;
cm->blue_mapping[i] = (DATA8) val2;
val2 = (int)cm->alpha_mapping[i] + val;
if (val2 < 0)
val2 = 0;
if (val2 > 255)
val2 = 255;
cm->alpha_mapping[i] = (DATA8) val2;
}
}
void
__imlib_CmodModContrast(ImlibColorModifier * cm, double v)
{
int i, val2;
for (i = 0; i < 256; i++)
{
val2 = (int)(((double)cm->red_mapping[i] - 127) * v) + 127;
if (val2 < 0)
val2 = 0;
if (val2 > 255)
val2 = 255;
cm->red_mapping[i] = (DATA8) val2;
val2 = (int)(((double)cm->green_mapping[i] - 127) * v) + 127;
if (val2 < 0)
val2 = 0;
if (val2 > 255)
val2 = 255;
cm->green_mapping[i] = (DATA8) val2;
val2 = (int)(((double)cm->blue_mapping[i] - 127) * v) + 127;
if (val2 < 0)
val2 = 0;
if (val2 > 255)
val2 = 255;
cm->blue_mapping[i] = (DATA8) val2;
val2 = (int)(((double)cm->alpha_mapping[i] - 127) * v) + 127;
if (val2 < 0)
val2 = 0;
if (val2 > 255)
val2 = 255;
cm->alpha_mapping[i] = (DATA8) val2;
}
}
void
__imlib_CmodModGamma(ImlibColorModifier * cm, double v)
{
int i, val2;
if (v < 0.01)
v = 0.01;
for (i = 0; i < 256; i++)
{
val2 = (int)(pow(((double)cm->red_mapping[i] / 255), (1 / v)) * 255);
if (val2 < 0)
val2 = 0;
if (val2 > 255)
val2 = 255;
cm->red_mapping[i] = (DATA8) val2;
val2 = (int)(pow(((double)cm->green_mapping[i] / 255), (1 / v)) * 255);
if (val2 < 0)
val2 = 0;
if (val2 > 255)
val2 = 255;
cm->green_mapping[i] = (DATA8) val2;
val2 = (int)(pow(((double)cm->blue_mapping[i] / 255), (1 / v)) * 255);
if (val2 < 0)
val2 = 0;
if (val2 > 255)
val2 = 255;
cm->blue_mapping[i] = (DATA8) val2;
val2 = (int)(pow(((double)cm->alpha_mapping[i] / 255), (1 / v)) * 255);
if (val2 < 0)
val2 = 0;
if (val2 > 255)
val2 = 255;
cm->alpha_mapping[i] = (DATA8) val2;
}
}
#if 0
void
__imlib_ImageCmodApply(ImlibImage * im, ImlibColorModifier * cm)
{
__imlib_DataCmodApply(im->data, im->w, im->h, 0, cm);
}
#endif

72
src/lib/colormod.h Normal file
View File

@ -0,0 +1,72 @@
#ifndef __COLORMOD
#define __COLORMOD 1
#include "common.h"
#include <time.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <ctype.h>
#include <errno.h>
#include "image.h"
typedef struct _imlib_color_modifier ImlibColorModifier;
struct _imlib_color_modifier
{
DATA8 red_mapping[256];
DATA8 green_mapping[256];
DATA8 blue_mapping[256];
DATA8 alpha_mapping[256];
DATABIG modification_count;
};
#define CMOD_APPLY_RGB(cm, r, g, b) \
(r) = (cm)->red_mapping[(int)(r)]; \
(g) = (cm)->green_mapping[(int)(g)]; \
(b) = (cm)->blue_mapping[(int)(b)];
#define CMOD_APPLY_RGBA(cm, r, g, b, a) \
(r) = (cm)->red_mapping[(int)(r)]; \
(g) = (cm)->green_mapping[(int)(g)]; \
(b) = (cm)->blue_mapping[(int)(b)]; \
(a) = (cm)->alpha_mapping[(int)(a)];
#define CMOD_APPLY_R(cm, r) \
(r) = (cm)->red_mapping[(int)(r)];
#define CMOD_APPLY_G(cm, g) \
(g) = (cm)->green_mapping[(int)(g)];
#define CMOD_APPLY_B(cm, b) \
(b) = (cm)->blue_mapping[(int)(b)];
#define CMOD_APPLY_A(cm, a) \
(a) = (cm)->alpha_mapping[(int)(a)];
#define R_CMOD(cm, r) \
(cm)->red_mapping[(int)(r)]
#define G_CMOD(cm, g) \
(cm)->green_mapping[(int)(g)]
#define B_CMOD(cm, b) \
(cm)->blue_mapping[(int)(b)]
#define A_CMOD(cm, a) \
(cm)->alpha_mapping[(int)(a)]
ImlibColorModifier * __imlib_CreateCmod(void);
void __imlib_FreeCmod(ImlibColorModifier *cm);
void __imlib_CmodChanged(ImlibColorModifier *cm);
void __imlib_CmodSetTables(ImlibColorModifier *cm, DATA8 *r,
DATA8 *g, DATA8 *b, DATA8 *a);
void __imlib_CmodReset(ImlibColorModifier *cm);
void __imlib_DataCmodApply(DATA32 *data, int w, int h,
int jump, ImlibImageFlags *fl,
ImlibColorModifier *cm);
void __imlib_CmodGetTables(ImlibColorModifier *cm, DATA8 *r,
DATA8 *g, DATA8 *b, DATA8 *a);
void __imlib_CmodModBrightness(ImlibColorModifier *cm,
double v);
void __imlib_CmodModContrast(ImlibColorModifier *cm,
double v);
void __imlib_CmodModGamma(ImlibColorModifier *cm,
double v);
#endif

42
src/lib/common.h Normal file
View File

@ -0,0 +1,42 @@
#ifndef __COMMON
#define __COMMON 1
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <config.h>
#include <string.h>
#ifdef WITH_DMALLOC
# include <dmalloc.h>
#endif
#ifdef __EMX__
#include <sys/types.h>
#endif
#define DATABIG unsigned long long
#define DATA64 unsigned long long
#define DATA32 unsigned int
#define DATA16 unsigned short
#define DATA8 unsigned char
#ifdef DO_MMX_ASM
int __imlib_get_cpuid(void);
#define CPUID_MMX (1 << 23)
#define CPUID_XMM (1 << 25)
#endif
#define CLIP(x, y, w, h, xx, yy, ww, hh) \
if (x < (xx)) {w += (x - (xx)); x = (xx);} \
if (y < (yy)) {h += (y - (yy)); y = (yy);} \
if ((x + w) > ((xx) + (ww))) {w = (ww) - (x - xx);} \
if ((y + h) > ((yy) + (hh))) {h = (hh) - (y - yy);}
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#ifdef __EMX__
extern char *__XOS2RedirRoot(const char *);
#endif
#endif

212
src/lib/context.c Normal file
View File

@ -0,0 +1,212 @@
#include "common.h"
#ifdef BUILD_X11
#include <X11/Xlib.h>
#endif
#include "image.h"
#include "context.h"
#include "color.h"
#include "rgba.h"
#ifdef BUILD_X11
static Context *context = NULL;
static int max_context_count = 128;
static int context_counter = 0;
void
__imlib_SetMaxContexts(int num)
{
max_context_count = num;
__imlib_FlushContexts();
}
int
__imlib_GetMaxContexts(void)
{
return max_context_count;
}
void
__imlib_FlushContexts(void)
{
Context *ct, *pct, *ctt;
ct = context;
pct = NULL;
while (ct)
{
ctt = ct;
ct = ct->next;
/* it hasnt been referenced in the last max_context_count refernces */
/* thus old and getrid of it */
if (ctt->last_use < (context_counter - max_context_count))
{
if (pct)
context = ctt->next;
else
pct->next = ctt->next;
if (ctt->palette)
{
int i, num[] = { 256, 128, 64, 32, 16, 8, 1 };
unsigned long pixels[256];
for (i = 0; i < num[ctt->palette_type]; i++)
pixels[i] = (unsigned long)ctt->palette[i];
XFreeColors(ctt->display, ctt->colormap, pixels,
num[ctt->palette_type], 0);
free(ctt->palette);
free(ctt->r_dither);
free(ctt->g_dither);
free(ctt->b_dither);
}
else if (ctt->r_dither)
{
free(ctt->r_dither);
free(ctt->g_dither);
free(ctt->b_dither);
}
free(ctt);
}
else
pct = ctt;
}
}
void
__imlib_FreeContextForDisplay(Display * d)
{
Context *ct;
ct = context;
while (ct)
{
if (ct->display == d)
ct->last_use = -(max_context_count * 2);
ct = ct->next;
}
__imlib_FlushContexts();
}
void
__imlib_FreeContextForColormap(Display * d, Colormap cm)
{
Context *ct;
ct = context;
while (ct)
{
if ((ct->display == d) && (ct->colormap == cm))
ct->last_use = -(max_context_count * 2);
ct = ct->next;
}
__imlib_FlushContexts();
}
void
__imlib_FreeContextForVisual(Display * d, Visual * v)
{
Context *ct;
ct = context;
while (ct)
{
if ((ct->display == d) && (ct->visual == v))
ct->last_use = -(max_context_count * 2);
ct = ct->next;
}
__imlib_FlushContexts();
}
Context *
__imlib_FindContext(Display * d, Visual * v, Colormap c, int depth)
{
Context *ct, *pct;
pct = NULL;
ct = context;
while (ct)
{
if ((ct->display == d) && (ct->visual == v) &&
(ct->colormap == c) && (ct->depth == depth))
{
if (pct)
{
pct->next = ct->next;
ct->next = context;
context = ct;
}
return ct;
}
pct = ct;
ct = ct->next;
}
return NULL;
}
Context *
__imlib_NewContext(Display * d, Visual * v, Colormap c, int depth)
{
Context *ct;
context_counter++;
ct = malloc(sizeof(Context));
ct->last_use = context_counter;
ct->display = d;
ct->visual = v;
ct->colormap = c;
ct->depth = depth;
ct->next = NULL;
if (depth <= 8)
{
ct->palette = __imlib_AllocColorTable(d, c, &(ct->palette_type), v);
ct->r_dither = malloc(sizeof(DATA8) * DM_X * DM_Y * 256);
ct->g_dither = malloc(sizeof(DATA8) * DM_X * DM_Y * 256);
ct->b_dither = malloc(sizeof(DATA8) * DM_X * DM_Y * 256);
__imlib_RGBA_init((void *)ct->r_dither, (void *)ct->g_dither,
(void *)ct->b_dither, depth, ct->palette_type);
}
else
{
ct->palette = NULL;
ct->palette_type = 0;
if ((depth > 8) && (depth <= 16))
{
ct->r_dither = malloc(sizeof(DATA16) * 4 * 4 * 256);
ct->g_dither = malloc(sizeof(DATA16) * 4 * 4 * 256);
ct->b_dither = malloc(sizeof(DATA16) * 4 * 4 * 256);
__imlib_RGBA_init((void *)ct->r_dither, (void *)ct->g_dither,
(void *)ct->b_dither, depth, 0);
}
else
{
ct->r_dither = NULL;
ct->g_dither = NULL;
ct->b_dither = NULL;
__imlib_RGBA_init((void *)ct->r_dither, (void *)ct->g_dither,
(void *)ct->b_dither, depth, 0);
}
}
return ct;
}
Context *
__imlib_GetContext(Display * d, Visual * v, Colormap c, int depth)
{
Context *ct;
ct = __imlib_FindContext(d, v, c, depth);
if (ct)
{
ct->last_use = context_counter;
return ct;
}
ct = __imlib_NewContext(d, v, c, depth);
ct->next = context;
context = ct;
__imlib_FlushContexts();
return ct;
}
#endif

36
src/lib/context.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef __CONTEXT
#define __CONTEXT 1
#ifdef BUILD_X11
typedef struct _context Context;
struct _context
{
int last_use;
Display *display;
Visual *visual;
Colormap colormap;
int depth;
Context *next;
DATA8 *palette;
DATA8 palette_type;
void *r_dither;
void *g_dither;
void *b_dither;
};
void __imlib_SetMaxContexts(int num);
int __imlib_GetMaxContexts(void);
void __imlib_FlushContexts(void);
void __imlib_FreeContextForDisplay(Display *d);
void __imlib_FreeContextForColormap(Display *d, Colormap cm);
void __imlib_FreeContextForVisual(Display *d, Visual *v);
Context *__imlib_FindContext(Display *d, Visual *v, Colormap c, int depth);
Context *__imlib_NewContext(Display *d, Visual *v, Colormap c, int depth);
Context *__imlib_GetContext(Display *d, Visual *v, Colormap c, int depth);
#endif
#endif

92
src/lib/draw.c Normal file
View File

@ -0,0 +1,92 @@
#include "common.h"
#ifdef BUILD_X11
#include <X11/Xlib.h>
#include <X11/extensions/XShm.h>
#endif
#include "colormod.h"
#include "image.h"
#include "blend.h"
#include "rend.h"
#include "draw.h"
#ifdef BUILD_X11
char
__imlib_CreatePixmapsForImage(Display * d, Drawable w, Visual * v, int depth,
Colormap cm, ImlibImage * im, Pixmap * p,
Mask * m, int sx, int sy, int sw, int sh, int dw,
int dh, char antialias, char hiq,
char dither_mask, ImlibColorModifier * cmod)
{
ImlibImagePixmap *ip = NULL;
Pixmap pmap = 0;
Pixmap mask = 0;
long long mod_count = 0;
if (cmod)
mod_count = cmod->modification_count;
ip = __imlib_FindCachedImagePixmap(im, dw, dh, d, v, depth, sx, sy,
sw, sh, cm, antialias, hiq, dither_mask,
mod_count);
if (ip)
{
if (p)
*p = ip->pixmap;
if (m)
*m = ip->mask;
ip->references++;
#ifdef DEBUG_CACHE
fprintf(stderr,
"[Imlib2] Match found in cache. Reference count is %d, pixmap 0x%08x, mask 0x%08x\n",
ip->references, ip->pixmap, ip->mask);
#endif
return 2;
}
if (p)
{
pmap = XCreatePixmap(d, w, dw, dh, depth);
*p = pmap;
}
if (m)
{
if (IMAGE_HAS_ALPHA(im))
mask = XCreatePixmap(d, w, dw, dh, 1);
*m = mask;
}
__imlib_RenderImage(d, im, pmap, mask, v, cm, depth, sx, sy, sw, sh, 0, 0,
dw, dh, antialias, hiq, 0, dither_mask, cmod, OP_COPY);
ip = __imlib_ProduceImagePixmap();
ip->visual = v;
ip->depth = depth;
ip->image = im;
if (im->file)
ip->file = strdup(im->file);
ip->border.left = im->border.left;
ip->border.right = im->border.right;
ip->border.top = im->border.top;
ip->border.bottom = im->border.bottom;
ip->colormap = cm;
ip->display = d;
ip->w = dw;
ip->h = dh;
ip->source_x = sx;
ip->source_y = sy;
ip->source_w = sw;
ip->source_h = sh;
ip->antialias = antialias;
ip->modification_count = mod_count;
ip->dither_mask = dither_mask;
ip->hi_quality = hiq;
ip->references = 1;
ip->pixmap = pmap;
ip->mask = mask;
__imlib_AddImagePixmapToCache(ip);
#ifdef DEBUG_CACHE
fprintf(stderr,
"[Imlib2] Created pixmap. Reference count is %d, pixmap 0x%08x, mask 0x%08x\n",
ip->references, ip->pixmap, ip->mask);
#endif
return 1;
}
#endif

16
src/lib/draw.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef __DRAW
#define __DRAW 1
#ifdef BUILD_X11
char
__imlib_CreatePixmapsForImage(Display *d, Drawable w, Visual *v, int depth,
Colormap cm, ImlibImage *im, Pixmap *p, Mask *m,
int sx, int sy, int sw, int sh,
int dw, int dh,
char anitalias, char hiq, char dither_mask,
ImlibColorModifier *cmod);
#endif
#endif

193
src/lib/dynamic_filters.c Normal file
View File

@ -0,0 +1,193 @@
#include "common.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <ctype.h>
#include <errno.h>
#include "image.h"
#include "file.h"
#include "dynamic_filters.h"
#include "script.h"
#include "loaderpath.h"
pImlibExternalFilter filters = NULL;
int dyn_initialised = 0;
#define MALLOCSHOW
#define FREESHOW
/*
#define FDEBUG
*/
pImlibExternalFilter
__imlib_LoadFilter(char *file)
{
ImlibExternalFilter *ptr;
struct imlib_filter_info *info;
/* printf( "Loading filter %s\n", file ); */
MALLOCSHOW;
ptr = malloc(sizeof(ImlibExternalFilter));
ptr->filename = strdup(file);
ptr->handle = dlopen(file, RTLD_NOW | RTLD_LOCAL);
if (!ptr->handle)
{
FREESHOW;
free(ptr->filename);
FREESHOW;
free(ptr);
return NULL;
}
ptr->init_filter = dlsym(ptr->handle, "init");
ptr->deinit_filter = dlsym(ptr->handle, "deinit");
ptr->exec_filter = dlsym(ptr->handle, "exec");
if (!ptr->init_filter || !ptr->deinit_filter || !ptr->exec_filter)
{
dlclose(ptr->handle);
FREESHOW;
free(ptr->filename);
FREESHOW;
free(ptr);
return NULL;
}
info = malloc(sizeof(struct imlib_filter_info));
ptr->init_filter(info);
ptr->num_filters = info->num_filters;
ptr->filters = info->filters;
ptr->name = info->name;
ptr->author = info->author;
ptr->description = info->description;
free(info);
#ifdef FDEBUG
printf("Filter has %d filters in it.\n", ptr->num_filters);
for (i = 0; i < ptr->num_filters; i++)
printf(" -> \"%s\"\n", ptr->filters[i]);
#endif
ptr->next = NULL;
return ptr;
}
void
__imlib_dynamic_filters_init()
{
char **list;
int num_filters, i = 0;
ImlibExternalFilter *ptr, *tptr;
if (!dyn_initialised)
{
MALLOCSHOW;
filters = malloc(sizeof(ImlibExternalFilter));
filters->filename = "";
filters->next = NULL;
ptr = filters;
#ifdef FDEBUG
printf("DEBUG: Dynamic filters Initisialising\n");
#endif
dyn_initialised = 1;
#ifdef FDEBUG
printf("DEBUG: Loading Filters\n");
#endif
list = __imlib_ListFilters(&num_filters);
for (i = num_filters - 1; i >= 0; i--)
{
tptr = NULL;
if ((tptr = __imlib_LoadFilter(list[i])) != NULL)
{
ptr->next = tptr;
ptr = ptr->next;
}
if (list[i])
{
FREESHOW;
free(list[i]);
}
}
FREESHOW;
if (list)
free(list);
}
}
void
__imlib_dynamic_filters_deinit()
{
}
pImlibExternalFilter
__imlib_get_dynamic_filter(char *name)
{
pImlibExternalFilter f_ptr;
int i = 0;
/* scan the filters */
for (f_ptr = filters->next; f_ptr != NULL; f_ptr = f_ptr->next)
{
/* scan the methods provided */
for (i = 0; i < f_ptr->num_filters; i++)
{
if (strcmp(f_ptr->filters[i], name) == 0)
{
#ifdef FDEBUG
printf("DEBUG: Found filter \"%s\"\n", name);
#endif
return f_ptr;
}
}
}
return NULL;
}
/* loader dir */
char **
__imlib_ListFilters(int *num_ret)
{
char **list = NULL, **l, *s;
int num, i, pi = 0;
*num_ret = 0;
/* same for system loader path */
s = (char *)malloc(sizeof(SYS_LOADERS_PATH) + 8 + 1);
sprintf(s, SYS_LOADERS_PATH "/filters");
#ifndef __EMX__
l = __imlib_FileDir(s, &num);
#else
l = __imlib_FileDir(__XOS2RedirRoot(s), &num);
#endif
if (num > 0)
{
*num_ret += num;
list = realloc(list, sizeof(char *) * *num_ret);
for (i = 0; i < num; i++)
{
s = (char *)realloc(s,
sizeof(SYS_LOADERS_PATH) + 9 + strlen(l[i]) +
1);
sprintf(s, SYS_LOADERS_PATH "/filters/%s", l[i]);
#ifndef __EMX__
list[pi + i] = strdup(s);
#else
list[pi + i] = strdup(__XOS2RedirRoot(s));
#endif
}
__imlib_FileFreeDirList(l, num);
}
free(s);
/* List currently contains *everything in there* we need to weed out
* the .so, .la, .a versions of the same loader or whatever else.
* dlopen can take an extension-less name and do the Right Thing
* with it, so that's what we'll give it. */
list = __imlib_TrimLoaderList(list, num_ret);
return list;
}

43
src/lib/dynamic_filters.h Normal file
View File

@ -0,0 +1,43 @@
#ifndef _DYNAMIC_FILTERS_H_
#define _DYNAMIC_FILTERS_H_
#include "script.h"
struct imlib_filter_info
{
char *name;
char *author;
char *description;
char **filters;
int num_filters;
};
typedef struct _imlib_external_filter ImlibExternalFilter;
typedef struct _imlib_external_filter *pImlibExternalFilter;
struct _imlib_external_filter
{
char *name;
char *author;
char *description;
int num_filters;
char *filename;
void *handle;
char **filters;
void (*init_filter)( struct imlib_filter_info *info );
void (*deinit_filter)();
void *(*exec_filter)( char *filter, void *im, pIFunctionParam params );
pImlibExternalFilter next;
};
void __imlib_dynamic_filters_init();
void __imlib_dynamic_filters_deinit();
pImlibExternalFilter __imlib_get_dynamic_filter( char *name );
char **__imlib_ListFilters(int *num_ret);
pImlibExternalFilter __imlib_LoadFilter( char *file );
#endif

737
src/lib/ellipse.c Normal file
View File

@ -0,0 +1,737 @@
#include "common.h"
#include "colormod.h"
#include "image.h"
#include "blend.h"
#include "span.h"
#include "updates.h"
#include "rgbadraw.h"
static void
__imlib_Ellipse_DrawToData(int xc, int yc, int a, int b, DATA32 color,
DATA32 *dst, int dstw, int clx, int cly, int clw, int clh,
ImlibOp op, char dst_alpha, char blend)
{
ImlibPointDrawFunction pfunc;
int xx, yy, x, y, prev_x, prev_y, ty, by, lx, rx;
DATA32 a2, b2, *tp, *bp;
DATA64 dx, dy;
if (A_VAL(&color) == 0xff)
blend = 0;
pfunc = __imlib_GetPointDrawFunction(op, dst_alpha, blend);
if (!pfunc)
return;
xc -= clx;
yc -= cly;
dst += (dstw * cly) + clx;
a2 = a*a; b2 = b*b;
yy = b << 16;
prev_y = b;
dx = a2 * b;
dy = 0;
ty = yc - b - 1;
by = yc + b;
lx = xc - 1;
rx = xc;
tp = dst + (dstw * ty) + lx;
bp = dst + (dstw * by) + lx;
while (dy < dx)
{
int len;
y = yy >> 16;
y += ((yy - (y << 16)) >> 15);
if (prev_y != y)
{
prev_y = y;
dx -= a2;
ty++; by--;
tp += dstw;
bp -= dstw;
}
len = rx - lx;
if (IN_RANGE(lx, ty, clw, clh))
pfunc(color, tp);
if (IN_RANGE(rx, ty, clw, clh))
pfunc(color, tp + len);
if (IN_RANGE(lx, by, clw, clh))
pfunc(color, bp);
if (IN_RANGE(rx, by, clw, clh))
pfunc(color, bp + len);
dy += b2;
yy -= ((dy << 16) / dx);
lx--; rx++;
tp--; bp--;
if ( (lx < 0) && (rx > clw) )
return;
if ( (ty > clh) || (by < 0) )
return;
}
xx = yy;
prev_x = xx >> 16;
dx = dy;
ty++;
by--;
tp += dstw;
bp -= dstw;
while (ty < yc)
{
int len;
x = xx >> 16;
x += ((xx - (x << 16)) >> 15);
if (prev_x != x)
{
prev_x = x;
dy += b2;
lx--; rx++;
tp--; bp--;
}
len = rx - lx;
if (IN_RANGE(lx, ty, clw, clh))
pfunc(color, tp);
if (IN_RANGE(rx, ty, clw, clh))
pfunc(color, tp + len);
if (IN_RANGE(lx, by, clw, clh))
pfunc(color, bp);
if (IN_RANGE(rx, by, clw, clh))
pfunc(color, bp + len);
dx -= a2;
xx += ((dx << 16) / dy);
ty++; by--;
tp += dstw;
bp -= dstw;
if ( (lx < 0) && (rx > clw) )
return;
if ( (ty > clh) || (by < 0) )
return;
}
}
static void
__imlib_Ellipse_DrawToData_AA(int xc, int yc, int a, int b, DATA32 color,
DATA32 *dst, int dstw, int clx, int cly, int clw, int clh,
ImlibOp op, char dst_alpha, char blend)
{
ImlibPointDrawFunction pfunc;
int xx, yy, x, y, prev_x, prev_y, ty, by, lx, rx;
DATA32 a2, b2, col0, col1, *tp, *bp;
DATA64 dx, dy;
DATA8 ca = A_VAL(&color);
pfunc = __imlib_GetPointDrawFunction(op, dst_alpha, blend);
if (!pfunc)
return;
xc -= clx;
yc -= cly;
dst += (dstw * cly) + clx;
col0 = col1 = color;
a2 = a*a; b2 = b*b;
yy = b << 16;
prev_y = b;
dx = a2 * b;
dy = 0;
ty = yc - b - 2;
by = yc + b + 1;
lx = xc - 1;
rx = xc;
tp = dst + (dstw * ty) + lx;
bp = dst + (dstw * by) + lx;
while (dy < dx)
{
int len;
DATA32 tmp;
y = yy >> 16;
if (prev_y != y)
{
prev_y = y;
dx -= a2;
ty++; by--;
tp += dstw;
bp -= dstw;
}
A_VAL(&col1) = (yy - (y << 16)) >> 8;
A_VAL(&col0) = 255 - A_VAL(&col1);
if (ca < 255)
{
MULT(A_VAL(&col0), ca, A_VAL(&col0), tmp)
MULT(A_VAL(&col1), ca, A_VAL(&col1), tmp)
}
len = rx - lx;
if (IN_RANGE(lx, ty, clw, clh))
pfunc(col1, tp);
if (IN_RANGE(lx, ty + 1, clw, clh))
pfunc(col0, tp + dstw);
if (IN_RANGE(rx, ty + 1, clw, clh))
pfunc(col0, tp + dstw + len);
if (IN_RANGE(rx, ty, clw, clh))
pfunc(col1, tp + len);
if (IN_RANGE(lx, by, clw, clh))
pfunc(col1, bp);
if (IN_RANGE(lx, by - 1, clw, clh))
pfunc(col0, bp - dstw);
if (IN_RANGE(rx, by - 1, clw, clh))
pfunc(col0, bp - dstw + len);
if (IN_RANGE(rx, by, clw, clh))
pfunc(col1, bp + len);
dy += b2;
yy -= ((dy << 16) / dx);
lx--; rx++;
tp--; bp--;
if ( (lx < 0) && (rx > clw) )
return;
if ( (ty > clh) || (by < 0) )
return;
}
y = yy >> 16;
xx = yy;
prev_x = y;
dx = dy;
ty++;
by--;
tp += dstw;
bp -= dstw;
while (ty < yc)
{
int len;
DATA32 tmp;
x = xx >> 16;
if (prev_x != x)
{
prev_x = x;
dy += b2;
lx--; rx++;
tp--; bp--;
}
A_VAL(&col1) = (xx - (x << 16)) >> 8;
A_VAL(&col0) = 255 - A_VAL(&col1);
if (ca < 255)
{
MULT(A_VAL(&col0), ca, A_VAL(&col0), tmp)
MULT(A_VAL(&col1), ca, A_VAL(&col1), tmp)
}
len = rx - lx;
if (IN_RANGE(lx, ty, clw, clh))
pfunc(col1, tp);
if (IN_RANGE(lx + 1, ty, clw, clh) && (x != y))
pfunc(col0, tp + 1);
if (IN_RANGE(rx - 1, ty, clw, clh) && (x != y))
pfunc(col0, tp + len - 1);
if (IN_RANGE(rx, ty, clw, clh))
pfunc(col1, tp + len);
if (IN_RANGE(lx, by, clw, clh))
pfunc(col1, bp);
if (IN_RANGE(lx + 1, by, clw, clh) && (x != y))
pfunc(col0, bp + 1);
if (IN_RANGE(rx - 1, by, clw, clh) && (x != y))
pfunc(col0, bp + len - 1);
if (IN_RANGE(rx, by, clw, clh))
pfunc(col1, bp + len);
dx -= a2;
xx += ((dx << 16) / dy);
ty++; by--;
tp += dstw;
bp -= dstw;
if ( (lx < 0) && (rx > clw) )
return;
if ( (ty > clh) || (by < 0) )
return;
}
}
static void
__imlib_Ellipse_FillToData(int xc, int yc, int a, int b, DATA32 color,
DATA32 *dst, int dstw, int clx, int cly, int clw, int clh,
ImlibOp op, char dst_alpha, char blend)
{
ImlibPointDrawFunction pfunc;
ImlibSpanDrawFunction sfunc;
int xx, yy, x, y, prev_x, prev_y, ty, by, lx, rx;
DATA32 a2, b2, *tp, *bp;
DATA64 dx, dy;
if (A_VAL(&color) == 0xff)
blend = 0;
pfunc = __imlib_GetPointDrawFunction(op, dst_alpha, blend);
sfunc = __imlib_GetSpanDrawFunction(op, dst_alpha, blend);
if ((!sfunc) || (!pfunc))
return;
xc -= clx;
yc -= cly;
dst += (dstw * cly) + clx;
a2 = a*a; b2 = b*b;
yy = b << 16;
prev_y = b;
dx = a2 * b;
dy = 0;
ty = yc - b - 1;
by = yc + b;
lx = xc - 1;
rx = xc;
tp = dst + (dstw * ty) + lx;
bp = dst + (dstw * by) + lx;
while (dy < dx)
{
int len;
DATA32 *tpp, *bpp;
y = yy >> 16;
y += ((yy - (y << 16)) >> 15);
if (prev_y != y)
{
prev_y = y;
dx -= a2;
ty++; by--;
tp += dstw;
bp -= dstw;
tpp = tp + 1;
bpp = bp + 1;
len = rx;
if (len > clw) len = clw;
len -= (lx + 1);
if (lx < -1)
{
len += (lx + 1);
tpp -= (lx + 1);
bpp -= (lx + 1);
}
if ( ((unsigned)(ty) < clh) && (len > 0) )
sfunc(color, tpp, len);
if ( ((unsigned)(by) < clh) && (len > 0) )
sfunc(color, bpp, len);
}
len = rx - lx;
if (IN_RANGE(lx, ty, clw, clh))
pfunc(color, tp);
if (IN_RANGE(rx, ty, clw, clh))
pfunc(color, tp + len);
if (IN_RANGE(lx, by, clw, clh))
pfunc(color, bp);
if (IN_RANGE(rx, by, clw, clh))
pfunc(color, bp + len);
dy += b2;
yy -= ((dy << 16) / dx);
lx--; rx++;
tp--; bp--;
if ( (ty > clh) || (by < 0) )
return;
}
xx = yy;
prev_x = xx >> 16;
dx = dy;
ty++;
by--;
tp += dstw;
bp -= dstw;
while (ty < yc)
{
int len;
DATA32 *tpp, *bpp;
x = xx >> 16;
x += ((xx - (x << 16)) >> 15);
if (prev_x != x)
{
prev_x = x;
dy += b2;
lx--; rx++;
tp--; bp--;
}
tpp = tp;
bpp = bp;
len = rx + 1;
if (len > clw) len = clw;
len -= lx;
if (lx < 0)
{
len += lx;
tpp -= lx;
bpp -= lx;
}
if ( ((unsigned)(ty) < clh) && (len > 0) )
sfunc(color, tpp, len);
if ( ((unsigned)(by) < clh) && (len > 0) )
sfunc(color, bpp, len);
dx -= a2;
xx += ((dx << 16) / dy);
ty++; by--;
tp += dstw;
bp -= dstw;
if ( (ty > clh) || (by < 0) )
return;
}
}
static void
__imlib_Ellipse_FillToData_AA(int xc, int yc, int a, int b, DATA32 color,
DATA32 *dst, int dstw, int clx, int cly, int clw, int clh,
ImlibOp op, char dst_alpha, char blend)
{
ImlibPointDrawFunction pfunc;
ImlibSpanDrawFunction sfunc;
int xx, yy, x, y, prev_x, prev_y, ty, by, lx, rx;
DATA32 a2, b2, col1, *tp, *bp;
DATA64 dx, dy;
DATA8 ca = A_VAL(&color);
pfunc = __imlib_GetPointDrawFunction(op, dst_alpha, blend);
if (ca == 0xff)
blend = 0;
sfunc = __imlib_GetSpanDrawFunction(op, dst_alpha, blend);
if ((!pfunc) || (!sfunc))
return;
xc -= clx;
yc -= cly;
dst += (dstw * cly) + clx;
col1 = color;
a2 = a*a; b2 = b*b;
yy = b << 16;
prev_y = b;
dx = a2 * b;
dy = 0;
ty = yc - b - 2;
by = yc + b + 1;
lx = xc - 1;
rx = xc;
tp = dst + (dstw * ty) + lx;
bp = dst + (dstw * by) + lx;
while (dy < dx)
{
int len;
DATA32 tmp, *tpp, *bpp;
y = yy >> 16;
if (prev_y != y)
{
prev_y = y;
dx -= a2;
ty++; by--;
tp += dstw;
bp -= dstw;
tpp = tp + 1;
bpp = bp + 1;
len = rx;
if (len > clw) len = clw;
len -= (lx + 1);
if (lx < -1)
{
len += (lx + 1);
tpp -= (lx + 1);
bpp -= (lx + 1);
}
if ( ((unsigned)(ty) < clh) && (len > 0) )
sfunc(color, tpp, len);
if ( ((unsigned)(by) < clh) && (len > 0) )
sfunc(color, bpp, len);
}
A_VAL(&col1) = ((yy - (y << 16)) >> 8);
if (ca < 255)
MULT(A_VAL(&col1), ca, A_VAL(&col1), tmp)
len = rx - lx;
if (IN_RANGE(lx, ty, clw, clh))
pfunc(col1, tp);
if (IN_RANGE(rx, ty, clw, clh))
pfunc(col1, tp + len);
if (IN_RANGE(lx, by, clw, clh))
pfunc(col1, bp);
if (IN_RANGE(rx, by, clw, clh))
pfunc(col1, bp + len);
dy += b2;
yy -= ((dy << 16) / dx);
lx--; rx++;
tp--; bp--;
if ( (ty > clh) || (by < 0) )
return;
}
y = yy >> 16;
xx = yy;
prev_x = y;
dx = dy;
ty++;
by--;
tp += dstw;
bp -= dstw;
while (ty < yc)
{
int len;
DATA32 tmp, *tpp, *bpp;
x = xx >> 16;
if (prev_x != x)
{
prev_x = x;
dy += b2;
lx--; rx++;
tp--; bp--;
}
tpp = tp + 1;
bpp = bp + 1;
len = rx;
if (len > clw) len = clw;
len -= (lx + 1);
if (lx < -1)
{
len += (lx + 1);
tpp -= (lx + 1);
bpp -= (lx + 1);
}
if ( ((unsigned)(ty) < clh) && (len > 0) )
sfunc(color, tpp, len);
if ( ((unsigned)(by) < clh) && (len > 0) )
sfunc(color, bpp, len);
A_VAL(&col1) = ((xx - (x << 16)) >> 8);
if (ca < 255)
MULT(A_VAL(&col1), ca, A_VAL(&col1), tmp)
len = rx - lx;
if (IN_RANGE(lx, ty, clw, clh))
pfunc(col1, tp);
if (IN_RANGE(rx, ty, clw, clh))
pfunc(col1, tp + len);
if (IN_RANGE(lx, by, clw, clh))
pfunc(col1, bp);
if (IN_RANGE(rx, by, clw, clh))
pfunc(col1, bp + len);
dx -= a2;
xx += ((dx << 16) / dy);
ty++; by--;
tp += dstw;
bp -= dstw;
if ( (ty > clh) || (by < 0) )
return;
}
}
void
__imlib_Ellipse_DrawToImage(int xc, int yc, int a, int b, DATA32 color,
ImlibImage *im, int clx, int cly, int clw, int clh,
ImlibOp op, char blend, char anti_alias)
{
int x, y, w, h;
if ((a == 0) || (b == 0))
{
(void) __imlib_Line_DrawToImage(xc - a, yc - b, xc + a, yc + b, color,
im, clx, cly, clw, clh,
op, blend, anti_alias, 0);
return;
}
if (blend && (!A_VAL(&color)))
return;
if (clw < 0)
return;
if (clw == 0)
{
clw = im->w;
clx = 0;
clh = im->h;
cly = 0;
}
CLIP_RECT_TO_RECT(clx, cly, clw, clh, 0, 0, im->w, im->h);
if ((clw < 1) || (clh < 1))
return;
if (a < 0) a = -a;
if (b < 0) b = -b;
if (a > 65535) a = 65535;
if (b > 65535) b = 65535;
w = 2 * (a + 1);
h = 2 * (b + 1);
x = xc - a - 1;
y = yc - b - 1;
if (anti_alias)
{
w += 2; h += 2;
x--; y--;
}
CLIP_RECT_TO_RECT(x, y, w, h, clx, cly, clw, clh);
if ((w < 1) || (h < 1))
return;
if (blend && IMAGE_HAS_ALPHA(im))
__imlib_build_pow_lut();
if (anti_alias)
__imlib_Ellipse_DrawToData_AA(xc, yc, a, b, color,
im->data, im->w, clx, cly, clw, clh,
op, IMAGE_HAS_ALPHA(im), blend);
else
__imlib_Ellipse_DrawToData(xc, yc, a, b, color,
im->data, im->w, clx, cly, clw, clh,
op, IMAGE_HAS_ALPHA(im), blend);
}
void
__imlib_Ellipse_FillToImage(int xc, int yc, int a, int b, DATA32 color,
ImlibImage *im, int clx, int cly, int clw, int clh,
ImlibOp op, char blend, char anti_alias)
{
int x, y, w, h;
if ((a == 0) || (b == 0))
{
(void) __imlib_Line_DrawToImage(xc - a, yc - b, xc + a, yc + b, color,
im, clx, cly, clw, clh,
op, blend, anti_alias, 0);
return;
}
if (blend && (!A_VAL(&color)))
return;
if (clw < 0)
return;
if (clw == 0)
{
clw = im->w;
clx = 0;
clh = im->h;
cly = 0;
}
CLIP_RECT_TO_RECT(clx, cly, clw, clh, 0, 0, im->w, im->h);
if ((clw < 1) || (clh < 1))
return;
if (a < 0) a = -a;
if (b < 0) b = -b;
if (a > 65535) a = 65535;
if (b > 65535) b = 65535;
w = 2 * (a + 1);
h = 2 * (b + 1);
x = xc - a - 1;
y = yc - b - 1;
if (anti_alias)
{
w += 2; h += 2;
x--; y--;
}
CLIP_RECT_TO_RECT(x, y, w, h, clx, cly, clw, clh);
if ((w < 1) || (h < 1))
return;
if (blend && IMAGE_HAS_ALPHA(im))
__imlib_build_pow_lut();
if (anti_alias)
__imlib_Ellipse_FillToData_AA(xc, yc, a, b, color,
im->data, im->w, clx, cly, clw, clh,
op, IMAGE_HAS_ALPHA(im), blend);
else
__imlib_Ellipse_FillToData(xc, yc, a, b, color,
im->data, im->w, clx, cly, clw, clh,
op, IMAGE_HAS_ALPHA(im), blend);
}

506
src/lib/file.c Normal file
View File

@ -0,0 +1,506 @@
#include "common.h"
#include <stdio.h>
#include <ctype.h>
#ifdef __EMX__
#include <sys/types.h>
#endif
#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
#include <pwd.h>
#include "file.h"
static void __imlib_FileFieldWord(char *s, int num, char *wd);
char *
__imlib_FileKey(const char *file)
{
char *newfile;
newfile = malloc(strlen(file) + 1);
if (!newfile)
return NULL;
newfile[0] = 0;
{
char *p1, *p2;
int go;
go = 0;
p1 = (char *)file;
p2 = newfile;
while (p1[0])
{
if (go)
{
p2[0] = p1[0];
p2++;
}
if ((p1[0] == ':') && (p1[1] != ':'))
go = 1;
if ((p1[0] == ':') && (p1[1] == ':'))
p1++;
p1++;
}
p2[0] = p1[0];
}
if (newfile[0])
return newfile;
else
free(newfile);
return NULL;
}
char *
__imlib_FileRealFile(const char *file)
{
char *newfile;
newfile = malloc(strlen(file) + 1);
if (!newfile)
return NULL;
newfile[0] = 0;
{
char *p1, *p2;
p1 = (char *)file;
p2 = newfile;
while (p1[0])
{
if (p1[0] == ':')
{
if (p1[1] == ':')
{
p2[0] = ':';
p2++;
p1++;
}
else
{
p2[0] = 0;
return newfile;
}
}
else
{
p2[0] = p1[0];
p2++;
}
p1++;
}
p2[0] = p1[0];
}
return newfile;
}
char *
__imlib_FileExtension(const char *file)
{
char *p;
char *fl;
fl = __imlib_FileRealFile(file);
if (!fl)
return strdup("");
p = strrchr(file, '.');
if (p)
{
char *ret;
ret = strdup(p + 1);
free(fl);
return ret;
}
free(fl);
return strdup("");
}
int
__imlib_FileExists(const char *s)
{
struct stat st;
char *fl;
if ((!s) || (!*s))
return 0;
if (__imlib_IsRealFile(s))
fl = strdup(s);
else
fl = __imlib_FileRealFile(s);
if (!fl)
return 0;
if (stat(fl, &st) < 0)
{
free(fl);
return 0;
}
free(fl);
return 1;
}
int
__imlib_FileIsFile(const char *s)
{
struct stat st;
char *fl;
if ((!s) || (!*s))
return 0;
if (__imlib_IsRealFile(s))
fl = strdup(s);
else
fl = __imlib_FileRealFile(s);
if (!fl)
return 0;
if (stat(fl, &st) < 0)
{
free(fl);
return 0;
}
if (S_ISREG(st.st_mode))
{
free(fl);
return 1;
}
free(fl);
return 0;
}
int
__imlib_FileIsDir(const char *s)
{
struct stat st;
char *fl;
if ((!s) || (!*s))
return 0;
if (__imlib_IsRealFile(s))
fl = strdup(s);
else
fl = __imlib_FileRealFile(s);
if (!fl)
return 0;
if (stat(fl, &st) < 0)
{
free(fl);
return 0;
}
if (S_ISDIR(st.st_mode))
{
free(fl);
return 1;
}
free(fl);
return 0;
}
int
__imlib_FilePermissions(const char *s)
{
struct stat st;
char *fl;
if ((!s) || (!*s))
return 0;
if (__imlib_IsRealFile(s))
fl = strdup(s);
else
fl = __imlib_FileRealFile(s);
if (!fl)
return 0;
if (stat(fl, &st) < 0)
{
free(fl);
return 0;
}
free(fl);
return st.st_mode;
}
int
__imlib_FileCanRead(const char *s)
{
char *fl;
int val;
if (__imlib_IsRealFile(s))
fl = strdup(s);
else
fl = __imlib_FileRealFile(s);
if (!fl)
return 0;
if (!(__imlib_FilePermissions(fl) & (S_IRUSR | S_IRGRP | S_IROTH)))
{
free(fl);
return 0;
}
val = (1 + access(fl, R_OK));
free(fl);
return val;
}
char **
__imlib_FileDir(char *dir, int *num)
{
int i, dirlen;
int done = 0;
DIR *dirp;
char **names;
struct dirent *dp;
if ((!dir) || (!*dir))
return (0);
dirp = opendir(dir);
if (!dirp)
{
*num = 0;
return (NULL);
}
/* count # of entries in dir (worst case) */
for (dirlen = 0; (dp = readdir(dirp)) != NULL; dirlen++);
if (!dirlen)
{
closedir(dirp);
*num = dirlen;
return (NULL);
}
names = (char **)malloc(dirlen * sizeof(char *));
if (!names)
return (NULL);
rewinddir(dirp);
for (i = 0; i < dirlen;)
{
dp = readdir(dirp);
if (!dp)
break;
if ((strcmp(dp->d_name, ".")) && (strcmp(dp->d_name, "..")))
{
names[i] = strdup(dp->d_name);
i++;
}
}
if (i < dirlen)
dirlen = i; /* dir got shorter... */
closedir(dirp);
*num = dirlen;
/* do a simple bubble sort here to alphanumberic it */
while (!done)
{
done = 1;
for (i = 0; i < dirlen - 1; i++)
{
if (strcmp(names[i], names[i + 1]) > 0)
{
char *tmp;
tmp = names[i];
names[i] = names[i + 1];
names[i + 1] = tmp;
done = 0;
}
}
}
return (names);
}
void
__imlib_FileFreeDirList(char **l, int num)
{
if (!l)
return;
while (num--)
if (l[num])
free(l[num]);
free(l);
return;
}
void
__imlib_FileDel(char *s)
{
if ((!s) || (!*s))
return;
unlink(s);
return;
}
int
__imlib_IsRealFile(const char *s)
{
struct stat st;
return ((stat(s, &st) != -1) && (S_ISREG(st.st_mode)));
}
time_t
__imlib_FileModDate(const char *s)
{
struct stat st;
char *fl;
if ((!s) || (!*s))
return 0;
if (__imlib_IsRealFile(s))
fl = strdup(s);
else
fl = __imlib_FileRealFile(s);
if (!fl)
return 0;
if (stat(fl, &st) < 0)
{
free(fl);
return 0;
}
if (st.st_mtime > st.st_ctime)
{
free(fl);
return st.st_mtime;
}
free(fl);
return st.st_ctime;
}
char *
__imlib_FileHomeDir(int uid)
{
static int usr_uid = -1;
static char *usr_s = NULL;
char *s;
struct passwd *pwd;
#ifndef __EMX__
s = getenv("HOME");
if (s)
return strdup(s);
if (usr_uid < 0)
usr_uid = getuid();
if ((uid == usr_uid) && (usr_s))
{
return (strdup(usr_s));
}
pwd = getpwuid(uid);
if (pwd)
{
s = strdup(pwd->pw_dir);
if (uid == usr_uid)
usr_s = strdup(s);
return (s);
}
#else
if ((s = getenv("HOME")) != NULL)
return strdup(s);
else if ((s = getenv("TMP")) != NULL)
return strdup(s);
#endif
return NULL;
}
/* gets word number [num] in the string [s] and copies it into [wd] */
/* wd is NULL terminated. If word [num] does not exist wd = "" */
/* NB: this function now handles quotes so for a line: */
/* Hello to "Welcome sir - may I Help" Shub Foo */
/* Word 1 = Hello */
/* Word 2 = to */
/* Word 3 = Welcome sir - may I Help */
/* Word 4 = Shub */
/* word 5 = Foo */
char *
__imlib_FileField(char *s, int field)
{
char buf[4096];
buf[0] = 0;
__imlib_FileFieldWord(s, field + 1, buf);
if (buf[0])
{
if ((!strcmp(buf, "NULL")) || (!strcmp(buf, "(null)")))
return (NULL);
return (strdup(buf));
}
return (NULL);
}
static void
__imlib_FileFieldWord(char *s, int num, char *wd)
{
char *cur, *start, *end;
int count, inword, inquote, len;
if (!s)
return;
if (!wd)
return;
*wd = 0;
if (num <= 0)
return;
cur = s;
count = 0;
inword = 0;
inquote = 0;
start = NULL;
end = NULL;
while ((*cur) && (count < num))
{
if (inword)
{
if (inquote)
{
if (*cur == '"')
{
inquote = 0;
inword = 0;
end = cur;
count++;
}
}
else
{
if (isspace(*cur))
{
end = cur;
inword = 0;
count++;
}
}
}
else
{
if (!isspace(*cur))
{
if (*cur == '"')
{
inquote = 1;
start = cur + 1;
}
else
start = cur;
inword = 1;
}
}
if (count == num)
break;
cur++;
}
if (!start)
return;
if (!end)
end = cur;
if (end <= start)
return;
len = (int)(end - start);
if (len > 4000)
len = 4000;
if (len > 0)
{
strncpy(wd, start, len);
wd[len] = 0;
}
return;
}

20
src/lib/file.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef __FILE
#define __FILE 1
char *__imlib_FileKey(const char *file);
char *__imlib_FileRealFile(const char *file);
char *__imlib_FileExtension(const char *file);
int __imlib_FileExists(const char *s);
int __imlib_FileIsFile(const char *s);
int __imlib_FileIsDir(const char *s);
char **__imlib_FileDir(char *dir, int *num);
void __imlib_FileFreeDirList(char **l, int num);
void __imlib_FileDel(char *s);
time_t __imlib_FileModDate(const char *s);
char *__imlib_FileHomeDir(int uid);
char *__imlib_FileField(char *s, int field);
int __imlib_FilePermissions(const char *s);
int __imlib_FileCanRead(const char *s);
int __imlib_IsRealFile(const char *s);
#endif

Some files were not shown because too many files have changed in this diff Show More