]> git.draconx.ca Git - liblbx.git/commitdiff
Initial implementation of the lbximg tool.
authorNick Bowler <draconx@gmail.com>
Mon, 31 Dec 2007 01:31:15 +0000 (20:31 -0500)
committerNick Bowler <draconx@gmail.com>
Mon, 31 Dec 2007 01:43:08 +0000 (20:43 -0500)
acinclude.m4 [new file with mode: 0644]
configure.ac
src/.gitignore
src/Makefile.am
src/lbximg.c [new file with mode: 0644]

diff --git a/acinclude.m4 b/acinclude.m4
new file mode 100644 (file)
index 0000000..89db997
--- /dev/null
@@ -0,0 +1,229 @@
+dnl Borrowed from Transcode (http://www.transcoding.org/cgi-bin/transcode)
+
+dnl PKG_INIT(rptfile, errfile)
+dnl
+AC_DEFUN([PKG_INIT],
+[
+pkg_err="no"
+pkg_err_file="pkg_err_file"
+pkg_rpt_file="pkg_rpt_file"
+
+if test x"$1" != x"" ; then
+  pkg_rpt_file="$1"
+fi
+echo -n > $pkg_rpt_file
+
+if test x"$2" != x"" ; then
+  pkg_err_file="$2"
+fi
+echo -n > $pkg_err_file
+])
+
+
+dnl PKG_ERROR(name, object, req-enable, pkg, url, [error message])
+AC_DEFUN([PKG_ERROR],
+[
+pkg_err="yes"
+this_pkg_err="yes"
+
+prob=""
+if test x"$3" = x"required" ; then
+  prob="requirement failed"
+else
+  prob="option '--enable-$1' failed"
+fi
+
+cat >> $pkg_err_file <<EOF
+ERROR: $prob: $6
+$2 can be found in the following packages:
+  $4  $5
+
+EOF
+])
+
+
+dnl PKG_CHECK(pkg-name, def-enabled, var-name, pkgconfig-name, conf-script,
+dnl     header, lib, symbol)
+dnl Test for pkg-name, and define var-name_CFLAGS and var-name_LIBS
+dnl   and HAVE_var-name if found
+dnl
+dnl 1 name          name of package; required (pkg-config name if applicable)
+dnl 2 req-enable    enable  by default, 'required', 'yes' or 'no'; required
+dnl 3 var-name      name stub for variables, preferably uppercase; required
+dnl 4 conf-script   name of "-config" script or 'no'
+dnl 5 header        header file to check or 'none'
+dnl 6 lib           library to check or 'none'
+dnl 7 symbol        symbol from the library to check or ''
+dnl 8 pkg           package (pkg-config name if applicable)
+dnl 9 url           homepage for the package
+
+AC_DEFUN([PKG_CHECK],
+[
+if test x"$2" != x"required" ; then
+  AC_MSG_CHECKING([whether $1 support is requested])
+  AC_ARG_ENABLE($1,
+    AC_HELP_STRING([--enable-$1],
+      [build with $1 support ($2)]),
+    [case "${enableval}" in
+      yes) ;;
+      no)  ;;
+      *) AC_MSG_ERROR(bad value ${enableval} for --enable-$1) ;;
+    esac],
+    enable_$1="$2")
+  AC_MSG_RESULT($enable_$1)
+else
+  enable_$1="yes"
+fi
+
+AC_ARG_WITH($1-prefix,
+  AC_HELP_STRING([--with-$1-prefix=PFX],
+    [prefix where $1 is installed (/usr)]),
+  w_$1_p="$withval", w_$1_p="")
+
+AC_ARG_WITH($1-includes,
+  AC_HELP_STRING([--with-$1-includes=DIR],
+    [directory where $1 headers ($5) are installed (/usr/include)]),
+  w_$1_i="$withval", w_$1_i="")
+
+AC_ARG_WITH($1-libs,
+  AC_HELP_STRING([--with-$1-libs=DIR],
+    [directory where $1 libararies (lib$6.so) are installed (/usr/lib)]),
+  w_$1_l="$withval", w_$1_l="")
+
+have_$1="no"
+this_pkg_err="no"
+
+if test x"$enable_$1" = x"yes" ; then
+
+  dnl pkg-config
+
+  pkg_config_$1="no"
+  AC_MSG_CHECKING([for pkgconfig support for $1])
+  if test x"$PKG_CONFIG" != x"no" ; then
+    if $PKG_CONFIG $8 --exists ; then
+      pkg_config_$1="yes"
+    fi
+  fi
+  AC_MSG_RESULT($pkg_config_$1)
+
+  dnl *-config
+
+  if test x"$4" != x"no" ; then
+    if test x"$w_$1_p" != x"" ; then
+      if test -x $w_$1_p/bin/$4 ; then
+        $1_config="$w_$1_p/bin/$4"
+      fi
+    fi
+    AC_PATH_PROG($1_config, $4, no)
+  else
+    $1_config="no"
+  fi
+
+  # get and test the _CFLAGS
+
+  AC_MSG_CHECKING([how to determine $3_CFLAGS])
+  if test x"$w_$1_i" != x"" ; then
+    $1_ii="-I$w_$1_i"
+    AC_MSG_RESULT(user)
+  else
+    if test x"$pkg_config_$1" != x"no" ; then
+      $1_ii="`$PKG_CONFIG $8 --cflags`"
+      AC_MSG_RESULT(pkg-config)
+    else
+      if test x"$$1_config" != x"no" ; then
+        $1_ii="`$$1_config --cflags`"
+        AC_MSG_RESULT($$1_config)
+      else
+        if test x"$w_$1_p" != x"" ; then
+          $1_ii="-I$w_$1_p/include"
+          AC_MSG_RESULT(prefix)
+        else
+          $1_ii="-I/usr/include"
+          AC_MSG_RESULT(default)
+        fi
+      fi
+    fi
+  fi
+  ipaths="" ; xi=""
+  for i in $$1_ii ; do
+    case $i in
+      -I*) ipaths="$ipaths $i" ;;
+        *) xi="$xi $i" ;;
+    esac
+  done
+  $1_ii="$ipaths"
+  $1_ii="`echo $$1_ii | sed -e 's/  */ /g'`"
+  $3_EXTRA_CFLAGS="$$3_EXTRA_CFLAGS $xi"
+  $3_EXTRA_CFLAGS="`echo $$3_EXTRA_CFLAGS | sed -e 's/  */ /g'`"
+
+  if test x"$5" != x"none" ; then
+    save_CPPFLAGS="$CPPFLAGS"
+    CPPFLAGS="$CPPFLAGS $$1_ii"
+    AC_CHECK_HEADER([$5],
+      [$3_CFLAGS="$$1_ii"],
+      [PKG_ERROR($1, $5, $2, $8, $9, [cannot compile $5])])
+    CPPFLAGS="$save_CPPFLAGS"
+  fi
+
+  # get and test the _LIBS
+
+  AC_MSG_CHECKING([how to determine $3_LIBS])
+  if test x"$w_$1_l" != x"" ; then
+    $1_ll="-L$w_$1_l"
+    AC_MSG_RESULT(user)
+  else
+    if test x"$pkg_config_$1" != x"no" ; then
+      $1_ll="`$PKG_CONFIG $8 --libs`"
+      AC_MSG_RESULT(pkg-config)
+    else
+      if test x"$$1_config" != x"no" ; then
+        $1_ll="`$$1_config --libs`"
+        AC_MSG_RESULT($$1_config)
+      else
+        if test x"$w_$1_p" != x"" ; then
+          $1_ll="-L$w_$1_p${deflib}"
+          AC_MSG_RESULT(prefix)
+        else
+          $1_ll="-L/usr${deflib}"
+          AC_MSG_RESULT(default)
+        fi
+      fi
+    fi
+  fi
+  lpaths="" ; xlibs="" ; xlf=""
+  for l in $$1_ll ; do
+    case $l in
+      -L*) lpaths="$lpaths $l" ;;
+      -l*) test x"$l" != x"-l$6" && xlibs="$xlibs $l" ;;
+        *) xlf="$xlf $l" ;;
+    esac
+  done
+  $1_ll="$lpaths"
+  $1_ll="`echo $$1_ll | sed -e 's/  */ /g'`"
+  xl=""
+  for i in $xlibs $xlf ; do
+    echo " $$3_EXTRA_LIBS " | grep -vq " $i " && xl="$xl $i"
+  done
+  $3_EXTRA_LIBS="$$3_EXTRA_LIBS $xl"
+  $3_EXTRA_LIBS="`echo $$3_EXTRA_LIBS | sed -e 's/  */ /g'`"
+
+  if test x"$6" != x"none" ; then
+    save_LDFLAGS="$LDFLAGS"
+    LDFLAGS="$LDFLAGS $$1_ll"
+    AC_CHECK_LIB([$6], [$7],
+      [$3_LIBS="$$1_ll -l$6 $$3_EXTRA_LIBS"],
+      [PKG_ERROR($1, lib$6, $2, $8, $9, [cannot link against lib$6])],
+      [$$3_EXTRA_LIBS])
+    LDFLAGS="$save_LDFLAGS"
+  fi
+
+  if test x"$this_pkg_err" = x"no" ; then
+    have_$1="yes"
+  fi
+
+else
+  $3_CFLAGS=""
+  $3_LIBS=""  
+fi
+])
+
index 8458e71ee5a900dfb3054ca8fc05406d4c4ad7bc..48c392c08f517130c255b7852e95fe8af43a8b24 100644 (file)
@@ -9,12 +9,26 @@ AC_PROG_CC_C99
 AC_HEADER_ASSERT
 AC_C_BIGENDIAN
 
+# pkg-config
+PKG_INIT
+if test x"$PKG_CONFIG" = x""; then
+       AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
+fi
+
 dnl Dirty hack to disable useless C++/Fortran checks
 AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG], [:])
 AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG], [:])
 
 AC_PROG_LIBTOOL
 
+# libpng
+PKG_CHECK(libpng, yes, [PNG], [libpng-config], [png.h], png,
+          png_create_write_struct, libpng, [http://www.libpng.org/])
+AC_SUBST(PNG_CFLAGS)
+AC_SUBST(PNG_LIBS)
+
+AM_CONDITIONAL([BUILD_LBXIMG], [test x"$have_libpng" = x"yes"])
+
 AC_CONFIG_FILES([
        Makefile
        src/Makefile
index 72d6853a669d07fbcf9b711384c4f3e01da68942..fc613284ce699494b8490facb1d33179e3387d2a 100644 (file)
@@ -6,3 +6,4 @@ Makefile.in
 *.lo
 *.la
 lbxtool
+lbximg
index 8bec70027a5f9eb8f4221e5f21da66b4f69e4853..f9958b9515ad73770dcc7f14ad74dc25915a89ff 100644 (file)
@@ -1,8 +1,15 @@
 lib_LTLIBRARIES   = liblbx.la
-bin_PROGRAMS      = lbxtool
+bin_PROGRAMS      = lbxtool lbximg
 include_HEADERS   = lbx.h
 
 liblbx_la_SOURCES = byteorder.h misc.h misc.c lbx.c image.c
 
 lbxtool_SOURCES   = lbxtool.c
 lbxtool_LDADD     = liblbx.la
+
+if BUILD_LBXIMG
+lbximg_SOURCES    = lbximg.c
+lbximg_LDADD      = liblbx.la
+lbximg_CFLAGS     = $(PNG_CFLAGS)
+lbximg_LDFLAGS    = $(PNG_LIBS)
+endif
diff --git a/src/lbximg.c b/src/lbximg.c
new file mode 100644 (file)
index 0000000..0770049
--- /dev/null
@@ -0,0 +1,105 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <getopt.h>
+
+#include "image.h"
+#include "lbx.h"
+
+static const char *progname;
+#define errmsg(fmt, ...) (\
+       fprintf(stderr, "%s: " fmt, progname, __VA_ARGS__)\
+)
+
+enum {
+       MODE_NONE,
+       MODE_DECODE,
+       MODE_IDENT,
+};
+
+int main(int argc, char **argv)
+{
+       int mode = MODE_NONE, verbose = 0;
+       FILE *inf = stdin, *palf = NULL;
+       const char *name = "stdin";
+       LBX_IMG *img;
+       int opt;
+
+       static const char *sopts = "idvf:p:";
+       static const struct option lopts[] = {
+               { "info",    0, NULL, 'i' },
+               { "decode",  0, NULL, 'd' },
+               { "verbose", 0, NULL, 'v' },
+               { "file",    1, NULL, 'f' },
+               { "palette", 1, NULL, 'p' },
+
+               { 0 }
+       };
+
+       progname = "lbximg"; /* argv[0]; */
+       while ((opt = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
+               switch(opt) {
+               case 'i':
+                       mode = MODE_IDENT;
+                       break;
+               case 'd':
+                       mode = MODE_DECODE;
+                       break;
+               case 'v':
+                       verbose = 1;
+                       break;
+               case 'f':
+                       if (strcmp(optarg, "-") == 0)
+                               break;
+
+                       name = strrchr(optarg, '/');
+                       name = name ? name+1 : optarg;
+
+                       inf = fopen(optarg, "rb");
+                       if (!inf) {
+                               errmsg("failed to open %s: %m\n", optarg);
+                               return EXIT_FAILURE;
+                       }
+                       break;
+               case 'p':
+                       palf = fopen(optarg, "rb");
+                       if (!palf) {
+                               errmsg("failed to open %s: %m\n", optarg);
+                               return EXIT_FAILURE;
+                       }
+
+                       break;
+               default:
+                       return EXIT_FAILURE;
+               }
+       }
+
+       if (mode == MODE_NONE) {
+               errmsg("you must specify a mode.\n", 0);
+               return EXIT_FAILURE;
+       }
+
+       img = lbximg_fopen(inf);
+       if (!img) {
+               errmsg("failed to open image: %s.\n", lbx_strerror());
+               return EXIT_FAILURE;
+       }
+
+       if (verbose || mode == MODE_IDENT) {
+               struct lbx_imginfo info;
+               lbximg_getinfo(img, &info);
+
+               printf("%s is %ux%u LBX image, %u frames\n",
+                      name, info.width, info.height, info.nframes);
+       }
+
+       switch (mode) {
+       case MODE_DECODE:
+               errmsg("decode function not yet implemented.\n", 0);
+               break;
+       }
+
+       lbximg_close(img);
+       return EXIT_SUCCESS;
+}