[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libcvd-members] libcvd configure configure.in Makefile.in cvd/i...
From: |
Edward Rosten |
Subject: |
[libcvd-members] libcvd configure configure.in Makefile.in cvd/i... |
Date: |
Thu, 28 Sep 2006 23:23:52 +0000 |
CVSROOT: /cvsroot/libcvd
Module name: libcvd
Changes by: Edward Rosten <edrosten> 06/09/28 23:23:51
Modified files:
. : configure configure.in Makefile.in
cvd : image_io.h
Added files:
cvd/internal/io: png.h
pnm_src : png.cc
progs : cvd_display_image.cxx
Log message:
PNG reading support.
This is lightly tested, so it may do strange things with some PNG files.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/internal/io/png.h?cvsroot=libcvd&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/libcvd/pnm_src/png.cc?cvsroot=libcvd&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/libcvd/configure?cvsroot=libcvd&r1=1.72&r2=1.73
http://cvs.savannah.gnu.org/viewcvs/libcvd/configure.in?cvsroot=libcvd&r1=1.70&r2=1.71
http://cvs.savannah.gnu.org/viewcvs/libcvd/Makefile.in?cvsroot=libcvd&r1=1.49&r2=1.50
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/image_io.h?cvsroot=libcvd&r1=1.30&r2=1.31
http://cvs.savannah.gnu.org/viewcvs/libcvd/progs/cvd_display_image.cxx?cvsroot=libcvd&rev=1.1
Patches:
Index: configure
===================================================================
RCS file: /cvsroot/libcvd/libcvd/configure,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -b -r1.72 -r1.73
--- configure 31 Jul 2006 14:42:18 -0000 1.72
+++ configure 28 Sep 2006 23:23:51 -0000 1.73
@@ -310,7 +310,7 @@
# include <unistd.h>
#endif"
-ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME
PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix
program_transform_name bindir sbindir libexecdir datadir sysconfdir
sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir
build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS AWK CC
CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CXX CXXFLAGS ac_ct_CXX build
build_cpu build_vendor build_os host host_cpu host_vendor host_os have_sse
have_mmxext have_sse2 have_64bit OFLAGS INSTALL_PROGRAM INSTALL_SCRIPT
INSTALL_DATA LN_S RANLIB ac_ct_RANLIB CXXCPP EGREP osx_hacks have_toon
have_lapack major minor have_dvbuffer have_v4l1buffer have_v4l2buffer
have_o2buffer have_qtbuffer have_videodisplay have_pthread have_jpeg have_tiff
have_ffmpeg fast_pointers fast_force docs cpu progs testprogs LIBOBJS LTLIBOBJS
debug_options debug_all_options'
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME
PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix
program_transform_name bindir sbindir libexecdir datadir sysconfdir
sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir
build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS AWK CC
CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CXX CXXFLAGS ac_ct_CXX build
build_cpu build_vendor build_os host host_cpu host_vendor host_os have_sse
have_mmxext have_sse2 have_64bit OFLAGS INSTALL_PROGRAM INSTALL_SCRIPT
INSTALL_DATA LN_S RANLIB ac_ct_RANLIB CXXCPP EGREP osx_hacks have_toon
have_lapack major minor have_dvbuffer have_v4l1buffer have_v4l2buffer
have_o2buffer have_qtbuffer have_videodisplay have_pthread have_jpeg have_tiff
have_png have_ffmpeg fast_pointers fast_force docs cpu progs testprogs LIBOBJS
LTLIBOBJS debug_options debug_all_options'
ac_subst_files=''
# Initialize some variables set by options.
@@ -876,6 +876,7 @@
--without-jpeg compile without JPEG support
--without-tiff compile without TIFF support
--with-tiff=forceold Debug/wierd build environment only. Force use of
older library facilities.
+ --without-png compile without PNG support
--without-ffmpeg compile without FFMPEG support
--with-fast-pointers=N Number of pointers for FAST detectors. Answer: 2
--with-fast-force=N Force first question position for FAST. Answer: 0,1
@@ -4262,7 +4263,7 @@
-all_options="videodisplay jpeg tiff ffmpeg toon lapack pthreads"
+all_options="videodisplay jpeg tiff png ffmpeg toon lapack pthreads"
dodginess_options=
################################################################################
@@ -7214,6 +7215,253 @@
+#Put this before TIFF. If libjpeg is static, then this will ensure
+#(hopefully) that it selected before libtiff is tested (libtiff may
+#depend on libjpeg)
+
+# Check whether --with-png or --without-png was given.
+if test "${with_png+set}" = set; then
+ withval="$with_png"
+ if test "$withval" = no; then disable_png=yes; else disable_png=no; fi
+fi;
+if test "$disable_png" != yes
+then
+
+for ac_header in png.h
+do
+as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+ echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
+else
+ # Is the header compilable?
+echo "$as_me:$LINENO: checking $ac_header usability" >&5
+echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+$ac_includes_default
+#include <$ac_header>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_cxx_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_header_compiler=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_header_compiler=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6
+
+# Is the header present?
+echo "$as_me:$LINENO: checking $ac_header presence" >&5
+echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+#include <$ac_header>
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+ (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } >/dev/null; then
+ if test -s conftest.err; then
+ ac_cpp_err=$ac_cxx_preproc_warn_flag
+ ac_cpp_err=$ac_cpp_err$ac_cxx_werror_flag
+ else
+ ac_cpp_err=
+ fi
+else
+ ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+ ac_header_preproc=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ ac_header_preproc=no
+fi
+rm -f conftest.err conftest.$ac_ext
+echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6
+
+# So? What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_cxx_preproc_warn_flag in
+ yes:no: )
+ { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler,
rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the
preprocessor!" >&2;}
+ { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the
compiler's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
+ ac_header_preproc=yes
+ ;;
+ no:yes:* )
+ { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be
compiled" >&5
+echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
+ { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing
prerequisite headers?" >&5
+echo "$as_me: WARNING: $ac_header: check for missing prerequisite
headers?" >&2;}
+ { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf
documentation" >&5
+echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
+ { echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But
Cannot Be Compiled\"" >&5
+echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be
Compiled\"" >&2;}
+ { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the
preprocessor's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result"
>&2;}
+ { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler
will take precedence" >&5
+echo "$as_me: WARNING: $ac_header: in the future, the compiler will take
precedence" >&2;}
+ (
+ cat <<\_ASBOX
+## ------------------------------ ##
+## Report this to the CVD lists. ##
+## ------------------------------ ##
+_ASBOX
+ ) |
+ sed "s/^/$as_me: WARNING: /" >&2
+ ;;
+esac
+echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ eval "$as_ac_Header=\$ac_header_preproc"
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
+
+fi
+if test `eval echo '${'$as_ac_Header'}'` = yes; then
+ cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
+echo "$as_me:$LINENO: checking for png_init_io in -lpng" >&5
+echo $ECHO_N "checking for png_init_io in -lpng... $ECHO_C" >&6
+if test "${ac_cv_lib_png_png_init_io+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ ac_check_lib_save_LIBS=$LIBS
+LIBS="-lpng $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+
+/* Override any gcc2 internal prototype to avoid an error. */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char png_init_io ();
+int
+main ()
+{
+png_init_io ();
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_cxx_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_lib_png_png_init_io=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_lib_png_png_init_io=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_lib_png_png_init_io" >&5
+echo "${ECHO_T}$ac_cv_lib_png_png_init_io" >&6
+if test $ac_cv_lib_png_png_init_io = yes; then
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBPNG 1
+_ACEOF
+
+ LIBS="-lpng $LIBS"
+
+fi
+
+ if test "$ac_cv_header_png_h" = yes && test
"$ac_cv_lib_png_png_init_io" = yes
+ then
+ cat >>confdefs.h <<\_ACEOF
+#define CVD_IMAGE_HAVE_PNG PNG,
+_ACEOF
+
+ have_png=yes
+
+ options="$options png"
+ fi
+fi
+
# Check whether --with-ffmpeg or --without-ffmpeg was given.
if test "${with_ffmpeg+set}" = set; then
@@ -7872,6 +8120,7 @@
progs/se3_post_mul toon
progs/se3_inv toon
progs/img_play videodisplay
+ progs/cvd_display_image videodisplay
progs/img_play_bw videodisplay
progs/img_play_deinterlace videodisplay
progs/video_play videodisplay ffmpeg
@@ -8582,6 +8831,7 @@
s,@have_pthread@,$have_pthread,;t t
s,@have_jpeg@,$have_jpeg,;t t
s,@have_tiff@,$have_tiff,;t t
+s,@have_png@,$have_png,;t t
s,@have_ffmpeg@,$have_ffmpeg,;t t
s,@fast_pointers@,$fast_pointers,;t t
s,@fast_force@,$fast_force,;t t
Index: configure.in
===================================================================
RCS file: /cvsroot/libcvd/libcvd/configure.in,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -b -r1.70 -r1.71
--- configure.in 31 Jul 2006 14:42:18 -0000 1.70
+++ configure.in 28 Sep 2006 23:23:51 -0000 1.71
@@ -376,7 +376,7 @@
>>)
changequote([,])
-all_options="videodisplay jpeg tiff ffmpeg toon lapack pthreads"
+all_options="videodisplay jpeg tiff png ffmpeg toon lapack pthreads"
dodginess_options=
################################################################################
@@ -888,6 +888,22 @@
+#Put this before TIFF. If libjpeg is static, then this will ensure
+#(hopefully) that it selected before libtiff is tested (libtiff may
+#depend on libjpeg)
+AC_ARG_WITH(png, [ --without-png compile without PNG support],[if
test "$withval" = no; then disable_png=yes; else disable_png=no; fi])
+if test "$disable_png" != yes
+then
+ AC_CHECK_HEADERS(png.h)
+ AC_CHECK_LIB(png, png_init_io)
+ if test "$ac_cv_header_png_h" = yes && test
"$ac_cv_lib_png_png_init_io" = yes
+ then
+ AC_DEFINE(CVD_IMAGE_HAVE_PNG, [PNG,])
+ AC_SUBST(have_png,yes)
+ options="$options png"
+ fi
+fi
+
AC_ARG_WITH(ffmpeg, [ --without-ffmpeg compile without FFMPEG
support],[if test "$withval" = no; then use_ffmpeg=no; else
use_ffmpeg="$withval"; fi])
if test "$use_ffmpeg" != no
then
@@ -1011,6 +1027,7 @@
progs/se3_post_mul toon
progs/se3_inv toon
progs/img_play videodisplay
+ progs/cvd_display_image videodisplay
progs/img_play_bw videodisplay
progs/img_play_deinterlace videodisplay
progs/video_play videodisplay ffmpeg
Index: Makefile.in
===================================================================
RCS file: /cvsroot/libcvd/libcvd/Makefile.in,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -b -r1.49 -r1.50
--- Makefile.in 28 Sep 2006 17:14:47 -0000 1.49
+++ Makefile.in 28 Sep 2006 23:23:51 -0000 1.50
@@ -134,6 +134,11 @@
CVD_OBJS+=pnm_src/jpeg.o
endif
+
+ifeq (@have_png@,yes)
+ CVD_OBJS+=pnm_src/png.o
+endif
+
ifeq (@have_ffmpeg@,yes)
CVD_OBJS+=cvd_src/videofilebuffer.o
endif
Index: cvd/image_io.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/image_io.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -b -r1.30 -r1.31
--- cvd/image_io.h 28 Sep 2006 00:28:32 -0000 1.30
+++ cvd/image_io.h 28 Sep 2006 23:23:51 -0000 1.31
@@ -46,6 +46,11 @@
#include <cvd/internal/io/tiff.h>
#endif
+
+#ifdef CVD_IMAGE_HAVE_PNG
+ #include <cvd/internal/io/png.h>
+#endif
+
namespace CVD
{
@@ -199,6 +204,12 @@
else if(c == 'I')
TIFF::readTIFF(im, i);
#endif
+#ifdef CVD_IMAGE_HAVE_PNG
+ else if(c == 0x89)
+ {
+ PNG::readPNG(im, i);
+ }
+#endif
else if(c == 'B')
BMP::readBMP(im, i);
else
Index: cvd/internal/io/png.h
===================================================================
RCS file: cvd/internal/io/png.h
diff -N cvd/internal/io/png.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ cvd/internal/io/png.h 28 Sep 2006 23:23:51 -0000 1.1
@@ -0,0 +1,275 @@
+#ifndef CVD_INTERNAL_IO_PNG_H
+#define CVD_INTERNAL_IO_PNG_H
+#include <iostream>
+#include <vector>
+#include <string>
+
+#include <cvd/image.h>
+#include <cvd/internal/load_and_save.h>
+#include <cvd/internal/convert_pixel_types.h>
+
+struct png_struct_def;
+struct png_info_struct;
+
+
+namespace CVD{
+namespace PNG{
+
+
+struct png_in
+{
+ enum
+ {
+ Grey,
+ GreyAlpha,
+ Rgb,
+ RgbAlpha
+ }colour_type;
+
+ png_in(std::istream&);
+ ~png_in();
+
+ void expand_depth_to_8();
+ void unpack_to_bytes();
+
+ void get_raw_pixel_lines(unsigned char**, int);
+ void get_raw_pixel_lines(unsigned short**, int);
+
+ void read_end();
+
+ int depth;
+ int width, height;
+ std::string error_string;
+
+ std::istream& i;
+
+ png_struct_def* png_ptr;
+ png_info_struct* info_ptr, *end_info;
+
+
+};
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// Utility
+//
+
+
+template<class C, class D> void make_row_pointers(SubImage<C>& im,
std::vector<D*>& rows)
+{
+ rows.resize(im.size().y);
+ for(int r=0; r < im.size().y; r++)
+ rows[r] = (D*)im[r];
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// Read Greyscale PNG
+//
+template<class Dest, class Src_ish> struct readPNG_grey
+{
+ static void read(SubImage<Dest>& im, png_in& png)
+ {
+ if(png.depth < 8)
+ png.expand_depth_to_8();
+
+ std::vector<Src_ish> row_buf(png.width);
+ Src_ish *row = &row_buf[0];
+
+ for(int r=0; r < png.height; r++)
+ {
+ png.get_raw_pixel_lines(&row, 1);
+ Pixel::ConvertPixels<Src_ish, Dest>::convert(row,
im[r], png.width);
+ }
+ }
+};
+
+template<class Dest> struct readPNG_grey<Dest, bool>
+{
+ static void read(SubImage<Dest>& im, png_in& png)
+ {
+ readPNG_grey<Dest, byte>::read(im, png);
+ }
+};
+
+template<> struct readPNG_grey<bool, bool>
+{
+ static void read(SubImage<bool>& im, png_in& png)
+ {
+ png.unpack_to_bytes();
+ std::vector<byte*> rows;
+ make_row_pointers(im, rows);
+ png.get_raw_pixel_lines(&rows[0], png.height);
+ }
+};
+
+template<> struct readPNG_grey<byte, unsigned char>
+{
+ static void read(SubImage<byte>& im, png_in& png)
+ {
+ if(png.depth < 8)
+ png.expand_depth_to_8();
+
+ std::vector<byte*> rows;
+ make_row_pointers(im, rows);
+
+ png.get_raw_pixel_lines(&rows[0], png.height);
+ }
+};
+
+
+template<> struct readPNG_grey<unsigned short, unsigned short>
+{
+ static void read(SubImage<unsigned short>& im, png_in& png)
+ {
+ std::vector<unsigned short*> rows;
+ make_row_pointers(im, rows);
+ png.get_raw_pixel_lines(&rows[0], png.height);
+ }
+};
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// Read RGB PNG
+//
+
+template<class Dest, class Src> struct readPNG_rgb
+{
+ static void read(SubImage<Dest>& im, png_in& png)
+ {
+ std::vector<Src> row_buf(png.width*3);
+ Src* row = &row_buf[0];
+
+ for(int r=0; r < png.height; r++)
+ {
+ png.get_raw_pixel_lines(&row, 1);
+ Pixel::ConvertPixels<Rgb<Src>, Dest
>::convert(reinterpret_cast<Rgb<Src>*>(row), im[r], png.width);
+ }
+ }
+};
+
+template<> struct readPNG_rgb<Rgb<byte>, byte>
+{
+ static void read(SubImage<Rgb<byte> >& im, png_in& png)
+ {
+ std::vector<byte*> rows;
+ make_row_pointers(im, rows);
+ png.get_raw_pixel_lines(&rows[0] , png.height);
+ }
+};
+
+template<> struct readPNG_rgb<Rgb<unsigned short>, unsigned short>
+{
+ static void read(SubImage<Rgb<byte> >& im, png_in& png)
+ {
+ std::vector<unsigned short*> rows;
+ make_row_pointers(im, rows);
+ png.get_raw_pixel_lines(&rows[0], png.height);
+ }
+};
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// Read RGBA PNG
+//
+
+template<class Dest, class Src> struct readPNG_rgba
+{
+ static void read(SubImage<Dest>& im, png_in& png)
+ {
+ std::vector<Src> row_buf(png.width*4);
+ Src* row = &row_buf[0];
+
+ for(int r=0; r < png.height; r++)
+ {
+ png.get_raw_pixel_lines(&row, 1);
+ Pixel::ConvertPixels<Rgba<Src>, Dest
>::convert(reinterpret_cast<Rgba<Src>*>(row), im[r], png.width);
+ }
+ }
+};
+
+template<> struct readPNG_rgb<Rgba<byte>, byte>
+{
+ static void read(SubImage<Rgba<byte> >& im, png_in& png)
+ {
+ std::vector<byte*> rows;
+ make_row_pointers(im, rows);
+ png.get_raw_pixel_lines(&rows[0] , png.height);
+ }
+};
+
+template<> struct readPNG_rgb<Rgba<unsigned short>, unsigned short>
+{
+ static void read(SubImage<Rgba<byte> >& im, png_in& png)
+ {
+ std::vector<unsigned short*> rows;
+ make_row_pointers(im, rows);
+ png.get_raw_pixel_lines(&rows[0], png.height);
+ }
+};
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// Runtime switch on type
+//
+
+template<class C> void readPNG(SubImage<C>& im, png_in& png)
+{
+ switch(png.colour_type)
+ {
+ case png_in::Grey:
+ if(png.depth == 16)
+ readPNG_grey<C, unsigned
short>::read(im, png);
+ else if(png.depth == 1)
+ readPNG_grey<C, bool>::read(im, png);
+ else
+ readPNG_grey<C, unsigned
char>::read(im, png);
+ break;
+
+ case png_in::GreyAlpha:
+ throw
Exceptions::Image_IO::UnsupportedImageSubType("PNG", "Grey-alpha not yet
supported");
+ break;
+
+ case png_in::Rgb:
+ if(png.depth == 16)
+ readPNG_rgb<C, unsigned
short>::read(im, png);
+ else
+ readPNG_rgb<C, unsigned char>::read(im,
png);
+ break;
+
+ case png_in::RgbAlpha:
+ if(png.depth == 16)
+ readPNG_rgba<C, unsigned
short>::read(im, png);
+ else
+ readPNG_rgba<C, unsigned
char>::read(im, png);
+ break;
+ }
+
+ //This clears the stream of PNGs
+ png.read_end();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// Adapter for various image manifestations
+//
+
+template <class T> void readPNG(SubImage<T>& im, std::istream& in)
+{
+ png_in png(in);
+ ImageRef size(png.width, png.height);
+ if (im.size() != size)
+ throw Exceptions::Image_IO::ImageSizeMismatch(size, im.size());
+ readPNG(im, png);
+}
+
+template <class T> void readPNG(Image<T>& im, std::istream& in)
+{
+ png_in png(in);
+ ImageRef size(png.width, png.height);
+ im.resize(size);
+ readPNG(im, png);
+}
+
+}}
+#endif
Index: pnm_src/png.cc
===================================================================
RCS file: pnm_src/png.cc
diff -N pnm_src/png.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ pnm_src/png.cc 28 Sep 2006 23:23:51 -0000 1.1
@@ -0,0 +1,180 @@
+#include "cvd/internal/io/png.h"
+#include "cvd/image_io.h"
+#include "cvd/config.h"
+
+#include <png.h>
+
+using namespace CVD;
+using namespace PNG;
+using namespace std;
+
+
+static void error_fn(png_structp png_ptr, png_const_charp error_msg)
+{
+ *(string*)(png_ptr->error_ptr) = error_msg;
+}
+
+static void warn_fn(png_structp png_ptr, png_const_charp error_msg)
+{
+}
+
+static void read_fn(png_structp png_ptr, unsigned char* data, size_t numbytes)
+{
+ istream* i = (istream*)png_get_io_ptr(png_ptr);
+ i->read((char*) data, numbytes);
+
+ //What to do on stream failure?
+ //There is no return value, and I do not know if longjmp is safe here.
+ //Anyway, multiple rereads of the data will cause the PNG read
+ //to fail because it has internal checksums
+}
+
+
+
+/*
+static void write_fn(png_structp png_ptr, unsigned char* data, size_t
numbytes)
+{
+ ostream* o = (ostream*)png_get_io_ptr(png_ptr);
+ o->write((char*) data, numbytes);
+}
+
+static void flush_fn(png_structp png_ptr)
+{
+ ostream* o = (ostream*)png_get_io_ptr(png_ptr);
+ (*o) << flush;
+}
+*/
+
+void png_in::unpack_to_bytes()
+{
+ //No error checking. Only call for Grey images
+ png_set_packing(png_ptr);
+}
+
+void png_in::expand_depth_to_8()
+{
+ //No error checking. Only call for Grey images
+ png_set_gray_1_2_4_to_8(png_ptr);
+}
+
+void png_in::get_raw_pixel_lines(unsigned char** row_ptr, int nlines)
+{
+ if(depth == 16)
+ throw Exceptions::Image_IO::ReadTypeMismatch(1);
+
+ if(setjmp(png_jmpbuf(png_ptr)))
+ throw Exceptions::Image_IO::MalformedImage(error_string);
+
+ //NB no check for read past end.
+ png_read_rows(png_ptr, row_ptr, NULL, nlines);
+}
+
+
+void png_in::get_raw_pixel_lines(unsigned short** row_ptr, int nlines)
+{
+ if(depth != 16)
+ throw Exceptions::Image_IO::ReadTypeMismatch(0);
+
+ if(setjmp(png_jmpbuf(png_ptr)))
+ throw Exceptions::Image_IO::MalformedImage(error_string);
+
+ //NB no check for read past end.
+ png_read_rows(png_ptr, (unsigned char**)row_ptr, NULL, nlines);
+}
+
+png_in::png_in(std::istream& in)
+:i(in)
+{
+ unsigned char header[8];
+ fread(header, 1, 8, stdin);
+
+ if(png_sig_cmp(header, 0, 8))
+ {
+ throw Exceptions::Image_IO::MalformedImage("Not a PNG image");
+ exit(1);
+ }
+
+
+ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL,
NULL);
+
+
+ if(!png_ptr)
+ throw Exceptions::OutOfMemory();
+
+ info_ptr = png_create_info_struct(png_ptr);
+ if(!info_ptr)
+ {
+ png_destroy_read_struct(&png_ptr, NULL, NULL);
+ throw Exceptions::OutOfMemory();
+ }
+
+ end_info = png_create_info_struct(png_ptr);
+ if(!info_ptr)
+ {
+ png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
+ throw Exceptions::OutOfMemory();
+ }
+
+ if(setjmp(png_jmpbuf(png_ptr)))
+ {
+ png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+ throw Exceptions::Image_IO::MalformedImage(error_string);
+ }
+
+ png_set_error_fn(png_ptr, &error_string, error_fn, warn_fn);
+
+ //png_init_io(png_ptr, stdin);
+
+ png_set_read_fn(png_ptr, &i, read_fn);
+
+
+ png_set_sig_bytes(png_ptr, 8);
+
+ png_read_info(png_ptr, info_ptr);
+
+ png_uint_32 w, h;
+ int colour, interlace, dummy;
+
+ png_get_IHDR(png_ptr, info_ptr, &w, &h, &depth, &colour, &interlace,
&dummy, &dummy);
+
+ width = w;
+ height = h;
+
+ if(colour & PNG_COLOR_MASK_COLOR)
+ if(colour & PNG_COLOR_MASK_ALPHA)
+ colour_type = RgbAlpha;
+ else
+ colour_type = Rgb;
+ else
+ if(colour & PNG_COLOR_MASK_ALPHA)
+ colour_type = GreyAlpha;
+ else
+ colour_type = Grey;
+
+ //Get rid of palette, by transforming it to RGB
+ if(colour == PNG_COLOR_TYPE_PALETTE)
+ png_set_palette_to_rgb(png_ptr);
+
+ if(interlace != PNG_INTERLACE_NONE)
+ throw Exceptions::Image_IO::UnsupportedImageSubType("PNG",
"Interlace not yet supported");
+
+ #ifdef CVD_ARCH_LITTLE_ENDIAN
+ if(depth == 16)
+ png_set_swap(png_ptr);
+ #endif
+}
+
+void png_in::read_end()
+{
+ //It doesn't matter if there's an error here
+ if(!setjmp(png_jmpbuf(png_ptr)))
+ png_read_end(png_ptr, end_info);
+}
+
+png_in::~png_in()
+{
+ //Destroy all PNG structs
+ png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+}
+
+
Index: progs/cvd_display_image.cxx
===================================================================
RCS file: progs/cvd_display_image.cxx
diff -N progs/cvd_display_image.cxx
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ progs/cvd_display_image.cxx 28 Sep 2006 23:23:51 -0000 1.1
@@ -0,0 +1,57 @@
+/*
+ This file is part of the CVD Library.
+
+ Copyright (C) 2005 The Authors
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include <cvd/image_io.h>
+#include <cvd/videodisplay.h>
+#include <cvd/gl_helpers.h>
+
+#include <iostream>
+
+using namespace CVD;
+using namespace std;
+
+int main()
+{
+ try
+ {
+ Image<Rgb<byte> > i = img_load(cin);
+
+
+ VideoDisplay d(i.size());
+
+ d.select_events(ExposureMask|KeyPressMask);
+
+ for(;;)
+ {
+ glDrawPixels(i);
+
+ XEvent e;
+ d.get_event(&e);
+
+ if(e.type == KeyPress)
+ return 0;
+ }
+ }
+ catch(Exceptions::All a)
+ {
+ cerr << "Error: " << a.what << endl;
+ }
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libcvd-members] libcvd configure configure.in Makefile.in cvd/i...,
Edward Rosten <=