mirror of
https://asciireactor.com/otho/cloudy-agn.git
synced 2024-12-04 18:45:07 +00:00
removed png
This commit is contained in:
parent
4f21d575d8
commit
61501726f2
@ -1,4 +0,0 @@
|
||||
png++ is written by Alexander Shulgin (alex dot shulgin at gmail dot com)
|
||||
Copyright (C) 2007,2008
|
||||
|
||||
When writing to me be sure to put png++: in the subject :-)
|
@ -1,13 +0,0 @@
|
||||
This file lists known bugs and limitations in png++:
|
||||
|
||||
- Lacks support for output transformations
|
||||
|
||||
- Lacks support for optional/unknown chunks in PNG data stream
|
||||
|
||||
- Documentation sucks
|
||||
|
||||
|
||||
To report bugs, please use Savannah bug tracker:
|
||||
http://savannah.nongnu.org/bugs/?group=pngpp&func=additem
|
||||
|
||||
Do not forget to check if the bug was already filed. :-)
|
@ -1,25 +0,0 @@
|
||||
Copying png++ is subject to the following license:
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. The name of the author may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
@ -1,29 +0,0 @@
|
||||
2009-06-21 Alex Shulgin
|
||||
|
||||
* config.hpp: Added support for FreeBSD (detect endianness).
|
||||
Patch by <c.petrik.sosa@gmail.com>.
|
||||
|
||||
png++-0.2.3 19 Oct 2008
|
||||
|
||||
Fixed numerous `already defined' errors due to require_color_space
|
||||
implementation. Added `config.hpp'. Fixed `strerror' usage.
|
||||
Minor docs fixes.
|
||||
|
||||
png++-0.2.1 08 Dec 2007
|
||||
|
||||
Added support for tRNS chunk. Added non-std IO streams support.
|
||||
Fixed 16-bit endianness problems. Improved test script.
|
||||
|
||||
png++-0.2.0 08 Jul 2007
|
||||
|
||||
Major internal code refactoring. Added support for non-8-bit
|
||||
data, row-by-row IO, added docs, test suite and more. Fixed some
|
||||
bugs including interlace handling.
|
||||
|
||||
png++-0.1.1 07 Apr 2007
|
||||
|
||||
Added appropriate copyright notices.
|
||||
|
||||
png++-0.1.0 04 Feb 2007
|
||||
|
||||
Initial release.
|
File diff suppressed because it is too large
Load Diff
@ -1,81 +0,0 @@
|
||||
General
|
||||
=======
|
||||
|
||||
PNG++ comes as a set of header files and does not require compilation
|
||||
to be installed. For the same reason there are no binary packages for
|
||||
png++.
|
||||
|
||||
|
||||
Prerequisites
|
||||
=============
|
||||
|
||||
- png++ is known to work with libpng-1.2.x (probably, the 1.4.x
|
||||
flavour will work too)
|
||||
|
||||
- png++ compiles with g++-4.1. Other version should work well too,
|
||||
but I have not tested.
|
||||
|
||||
- png++ relies on GNU make for compiling tests and examples; in
|
||||
particular it uses "remaking makefiles" feature.
|
||||
|
||||
- Documentation is produced using doxygen (http://www.doxygen.org/).
|
||||
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
Follow these instructions in order to install png++:
|
||||
|
||||
- Unpack source package:
|
||||
|
||||
$ tar -zxf png++-0.2.x.tar.gz -C ~/src
|
||||
|
||||
- Go to your brand new png++ sources directory:
|
||||
|
||||
$ cd ~/src/png++-0.2.x
|
||||
|
||||
- Issue make to test how it's doing:
|
||||
|
||||
$ make
|
||||
|
||||
This will compile examples in the example/ directory.
|
||||
|
||||
As always, CFLAGS and LDFLAGS could be used to adjust compilation. In
|
||||
addition, you might want to specify custom libpng-config. Use
|
||||
LIBPNG_CONFIG variable for that purpose, like this:
|
||||
|
||||
$ make LIBPNG_CONFIG=~/bin/libpng-config
|
||||
|
||||
If everything goes well, try:
|
||||
|
||||
$ make test
|
||||
|
||||
(or "make check" which is the same as above). This will run the test
|
||||
suite. If tests do not produce error messages then probably all is
|
||||
OK.
|
||||
|
||||
- Now you can create documentation (optional). Use
|
||||
|
||||
$ make docs
|
||||
|
||||
to run doxygen in the sources directory.
|
||||
|
||||
- Now it is time to become root and install png++ into your system:
|
||||
|
||||
# make install
|
||||
|
||||
It's OK to issue "make install" under ordinary user permissions if you
|
||||
want to install png++ into your home directory. Run the following
|
||||
command:
|
||||
|
||||
$ make install PREFIX=$HOME
|
||||
|
||||
This will copy png++ header files to ~/include/png++ and documentation
|
||||
files to ~/share/doc/png++-0.2.x (if the docs were built).
|
||||
|
||||
Without a PREFIX png++ installs to /usr/local
|
||||
|
||||
|
||||
Happy hacking!
|
||||
--
|
||||
Alex Shulgin <alex.shulgin@gmail.com>
|
@ -1,148 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2007,2008 Alex Shulgin
|
||||
#
|
||||
# This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
# software; the exact copying conditions are as follows:
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# 3. The name of the author may not be used to endorse or promote products
|
||||
# derived from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
# NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
# don't forget to update version before releasing!
|
||||
version := 0.2.5
|
||||
|
||||
ifndef PREFIX
|
||||
PREFIX := /usr/local
|
||||
endif
|
||||
|
||||
ifdef MINGW
|
||||
bin_suffix := .exe
|
||||
endif
|
||||
|
||||
make_cflags := -Wall $(CFLAGS) -I$(PREFIX)/include
|
||||
make_ldflags := $(LDFLAGS) -L$(PREFIX)/lib
|
||||
|
||||
ifndef NDEBUG
|
||||
make_cflags := $(make_cflags) -g
|
||||
make_ldflags := $(make_ldflags) -g
|
||||
endif
|
||||
|
||||
ifndef LIBPNG_CONFIG
|
||||
LIBPNG_CONFIG := libpng-config
|
||||
endif
|
||||
|
||||
build_files := Makefile Doxyfile
|
||||
doc_files := AUTHORS BUGS ChangeLog COPYING INSTALL NEWS README TODO
|
||||
headers := *.hpp
|
||||
sources :=
|
||||
|
||||
dist_dir := png++-$(version)
|
||||
dist_package := png++-$(version).tar.gz
|
||||
dist_files := $(build_files) $(doc_files) \
|
||||
$(headers) $(sources)
|
||||
dist_subdirs := example test
|
||||
|
||||
all: examples
|
||||
|
||||
install: install-headers install-docs
|
||||
|
||||
uninstall: uninstall-headers uninstall-docs
|
||||
|
||||
install-headers:
|
||||
mkdir -p $(PREFIX)/include/png++
|
||||
cp *.hpp $(PREFIX)/include/png++
|
||||
|
||||
uninstall-headers:
|
||||
rm -rf $(PREFIX)/include/png++
|
||||
|
||||
dist: dist-mkdir dist-copy-files dist-package
|
||||
|
||||
dist-mkdir:
|
||||
rm -rf $(dist_dir)
|
||||
mkdir $(dist_dir)
|
||||
|
||||
dist-copy-files:
|
||||
cp $(dist_files) $(dist_dir)
|
||||
for i in $(dist_subdirs); do \
|
||||
$(MAKE) dist-copy-files -C $$i $(MAKEFLAGS) \
|
||||
dist_dir=`pwd`/$(dist_dir); \
|
||||
done
|
||||
|
||||
dist-package:
|
||||
rm -f $(dist_package)
|
||||
tar -zcf $(dist_package) $(dist_dir) --exclude=.svn --exclude='*~'
|
||||
rm -rf $(dist_dir)
|
||||
|
||||
clean: test-clean examples-clean
|
||||
# rm -f $(targets)
|
||||
|
||||
thorough-clean: clean docs-clean
|
||||
|
||||
check: test
|
||||
|
||||
test:
|
||||
$(MAKE) test -C test $(MAKEFLAGS) PNGPP=`pwd`
|
||||
|
||||
test-clean:
|
||||
$(MAKE) clean -C test $(MAKEFLAGS)
|
||||
|
||||
test-compile-headers: *.hpp
|
||||
for i in *.hpp; do \
|
||||
echo '#include "'$$i'"' >$$i.cpp \
|
||||
&& g++ -c $$i.cpp $(make_cflags) `$(LIBPNG_CONFIG) --cflags`; \
|
||||
done
|
||||
rm -f *.hpp.o *.hpp.cpp
|
||||
|
||||
docs:
|
||||
doxygen
|
||||
|
||||
docs-clean:
|
||||
rm -rf doc
|
||||
|
||||
install-docs:
|
||||
if [ -d doc ]; then \
|
||||
dir=$(PREFIX)/share/doc/$(dist_dir); \
|
||||
rm -rf $$dir; \
|
||||
mkdir -p $$dir \
|
||||
&& cp -r $(doc_files) doc/html $$dir; \
|
||||
cd $(PREFIX)/share/doc; \
|
||||
[ -L png++ ] && rm png++; \
|
||||
[ -d png++ ] || ln -s $(dist_dir) png++; \
|
||||
fi
|
||||
|
||||
uninstall-docs:
|
||||
rm -rf $(PREFIX)/share/doc/$(dist_dir) $(PREFIX)/share/doc/png++
|
||||
|
||||
examples:
|
||||
$(MAKE) -C example $(MAKEFLAGS)
|
||||
|
||||
examples-clean:
|
||||
$(MAKE) clean -C example $(MAKEFLAGS)
|
||||
|
||||
.PHONY: all install \
|
||||
dist dist-mkdir dist-copy-files dist-package \
|
||||
clean thorough-clean \
|
||||
check test test-clean test-compile-headers \
|
||||
docs docs-clean \
|
||||
examples examples-clean
|
@ -1,54 +0,0 @@
|
||||
Version 0.2.5:
|
||||
|
||||
- Fixed compatibility with newer libpng versions (>= 1.4)
|
||||
|
||||
- Fixed compilation on FreeBSD.
|
||||
|
||||
- Fixed tRNS handling with transformations.
|
||||
|
||||
- Added IO transformation debugging facility.
|
||||
|
||||
- Better organized test suite.
|
||||
|
||||
Version 0.2.3:
|
||||
|
||||
- Fixed numerous `already defined' errors due to require_color_space
|
||||
implementation.
|
||||
|
||||
- Added `config.hpp'.
|
||||
|
||||
- Fixed `strerror' usage.
|
||||
|
||||
- Minor docs fixes.
|
||||
|
||||
|
||||
Version 0.2.1:
|
||||
|
||||
- Added support for tRNS chunk.
|
||||
|
||||
- Added non-std IO streams support.
|
||||
|
||||
- Fixed 16-bit endianness problems.
|
||||
|
||||
- Improved test script.
|
||||
|
||||
|
||||
Version 0.2.0:
|
||||
|
||||
- Added support for 16-bit data (RGB, RGBA, Grayscale and Gray+Alpha
|
||||
color types)
|
||||
|
||||
- Added support for packed 1-, 2- or 4-bit pixels (Grayscale and
|
||||
Indexed colors)
|
||||
|
||||
- Fixed interlace handling code which was severely broken
|
||||
|
||||
- Added possibility to process images without reading the entire
|
||||
image into memory
|
||||
|
||||
- Internals are refactored while the client interface is mostly
|
||||
unchanged
|
||||
|
||||
- Added intensive test suite
|
||||
|
||||
- Added documentation
|
@ -1,20 +0,0 @@
|
||||
? add output transformations
|
||||
+ support for non-8bit data
|
||||
+ stream exceptions: badbit only
|
||||
+ adjust png::image for non-memory back end buffer + row-by-row io
|
||||
+ use doxygen
|
||||
- add optional and unknown chunks handling
|
||||
+ change bit_depth to size_t
|
||||
+ move tests sources to test/, examples to examples/
|
||||
+ extract common code from generator/consumer
|
||||
+ update pixel traits to detect channels count
|
||||
+ unify template parameters naming
|
||||
+ make sure all headers compile on their own
|
||||
+ add compilation dependency detection
|
||||
+ add pixel_buffer/image::operator[]
|
||||
+ improve docs and README
|
||||
? endianness in expand_8_to_16()
|
||||
- unify error messages (capitalization, etc.)
|
||||
+ move stream template parameter from class to function level in
|
||||
generator and consumer
|
||||
+ make all tests run even if any of them fails
|
@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_COLOR_HPP_INCLUDED
|
||||
#define PNGPP_COLOR_HPP_INCLUDED
|
||||
|
||||
#include "types.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief PNG color struct extension. Adds constructors.
|
||||
*/
|
||||
struct color
|
||||
: png_color
|
||||
{
|
||||
explicit color(byte r = 0, byte g = 0, byte b = 0)
|
||||
{
|
||||
this->red = r;
|
||||
this->green = g;
|
||||
this->blue = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Initializes color with a copy of png_color object.
|
||||
*/
|
||||
color(png_color const& other)
|
||||
{
|
||||
this->red = other.red;
|
||||
this->green = other.green;
|
||||
this->blue = other.blue;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_COLOR_HPP_INCLUDED
|
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_CONFIG_HPP_INCLUDED
|
||||
#define PNGPP_CONFIG_HPP_INCLUDED
|
||||
|
||||
// Endianness test
|
||||
#if defined(__GLIBC__)
|
||||
|
||||
#include <endian.h>
|
||||
|
||||
#elif defined(__WIN32)
|
||||
|
||||
#define __LITTLE_ENDIAN 1234
|
||||
#define __BIG_ENDIAN 4321
|
||||
#define __BYTE_ORDER __LITTLE_ENDIAN
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
#include <machine/endian.h>
|
||||
#include <sys/_endian.h>
|
||||
|
||||
#elif defined(__FreeBSD__)
|
||||
|
||||
#include <machine/endian.h>
|
||||
#include <sys/endian.h>
|
||||
|
||||
#else
|
||||
|
||||
#error Byte-order could not be detected.
|
||||
|
||||
#endif
|
||||
|
||||
#endif // PNGPP_CONFIG_HPP_INCLUDED
|
@ -1,257 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_CONSUMER_HPP_INCLUDED
|
||||
#define PNGPP_CONSUMER_HPP_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <istream>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "error.hpp"
|
||||
#include "streaming_base.hpp"
|
||||
#include "reader.hpp"
|
||||
#include "pixel_buffer.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Pixel consumer class template.
|
||||
*
|
||||
* Used as a base class for custom pixel consumer classes as well
|
||||
* as inside image class implementation to read pixels into the
|
||||
* pixel buffer.
|
||||
*
|
||||
* Encapsulates PNG %image reading procedure. In order to create
|
||||
* a custom pixel %consumer use CRTP trick:
|
||||
*
|
||||
* \code
|
||||
* class pixel_consumer
|
||||
* : public png::consumer< pixel, pixel_consumer >
|
||||
* {
|
||||
* ...
|
||||
* };
|
||||
* \endcode
|
||||
*
|
||||
* Your pixel %consumer class should implement \c get_next_row()
|
||||
* method and \c reset() method (optional). Their signatures are
|
||||
* as follows:
|
||||
*
|
||||
* \code
|
||||
* png::byte* get_next_row(size_t pos);
|
||||
* void reset(size_t pass);
|
||||
* \endcode
|
||||
*
|
||||
* The \c get_next_row() method is called every time a new row of
|
||||
* %image data is available to the reader. The position of the row
|
||||
* being read is passed as \c pos parameter. The \c pos takes
|
||||
* values from \c 0 to \c <image_height>-1 inclusively. The
|
||||
* method should return the starting address of a row buffer
|
||||
* capable of storing appropriate amount of pixels (i.e. the width
|
||||
* of the %image being read). The address should be casted to
|
||||
* png::byte* pointer type using \c reinterpret_cast<> or a
|
||||
* C-style cast.
|
||||
*
|
||||
* The optional \c reset() method is called every time the new
|
||||
* pass of interlaced %image processing starts. The number of
|
||||
* interlace pass is avaiable as the only parameter of the method.
|
||||
* For non-interlaced images the method is called once prior to
|
||||
* any calls to \c get_next_row(). The value of \c 0 is passed
|
||||
* for the \c pass number.
|
||||
*
|
||||
* An optional template parameter \c info_holder encapsulates
|
||||
* image_info storage policy. Using def_image_info_holder results
|
||||
* in image_info object stored as a sub-object of the consumer
|
||||
* class. You may specify image_info_ref_holder in order to use a
|
||||
* reference to the externally stored image_info object. This way
|
||||
* you will have to construct the consumer object passing the
|
||||
* reference to image_info object.
|
||||
*
|
||||
* Also, you might want implement an %info holder object yourself
|
||||
* to fine-tune your code. In any case, you can access the
|
||||
* image_info object from your %consumer class methods using the
|
||||
* following code:
|
||||
*
|
||||
* \code
|
||||
* png::image_info& info = m_info_holder.get_info();
|
||||
* \endcode
|
||||
*
|
||||
* An optional \c bool template parameter \c interlacing_supported
|
||||
* specifies whether reading interlacing images is supported by
|
||||
* your %consumer class. It defaults to \c false. An attempt to
|
||||
* read an interlaced %image will result in discarding pixels
|
||||
* obtained at all the interlacing passes except the last one.
|
||||
*
|
||||
* In order to fully support interlacing specify \c true for \c
|
||||
* interlacing_supported parameter and implement \c reset()
|
||||
* method.
|
||||
*
|
||||
* \see image, generator
|
||||
*/
|
||||
template< typename pixel,
|
||||
class pixcon,
|
||||
class info_holder = def_image_info_holder,
|
||||
bool interlacing_supported = false >
|
||||
class consumer
|
||||
: public streaming_base< pixel, info_holder >
|
||||
{
|
||||
public:
|
||||
typedef pixel_traits< pixel > traits;
|
||||
|
||||
/**
|
||||
* \brief The default io transformation: does nothing.
|
||||
*/
|
||||
struct transform_identity
|
||||
{
|
||||
void operator()(io_base&) const {}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Reads an image from the stream using default io
|
||||
* transformation.
|
||||
*/
|
||||
template< typename istream >
|
||||
void read(istream& stream)
|
||||
{
|
||||
read(stream, transform_identity());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads an image from the stream using custom io
|
||||
* transformation.
|
||||
*
|
||||
* Essentially, this method constructs a reader object and
|
||||
* instructs it to read the image from the stream. It handles
|
||||
* IO transformation, as well as interlaced image reading.
|
||||
*/
|
||||
template< typename istream, class transformation >
|
||||
void read(istream& stream, transformation const& transform)
|
||||
{
|
||||
reader< istream > rd(stream);
|
||||
rd.read_info();
|
||||
transform(rd);
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
if (pixel_traits< pixel >::get_bit_depth() == 16)
|
||||
{
|
||||
#ifdef PNG_READ_SWAP_SUPPORTED
|
||||
rd.set_swap();
|
||||
#else
|
||||
throw error("Cannot read 16-bit image:"
|
||||
" recompile with PNG_READ_SWAP_SUPPORTED.");
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// interlace handling _must_ be set up prior to info update
|
||||
size_t pass_count;
|
||||
if (rd.get_interlace_type() != interlace_none)
|
||||
{
|
||||
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
||||
pass_count = rd.set_interlace_handling();
|
||||
#else
|
||||
throw error("Cannot read interlaced image:"
|
||||
" interlace handling disabled.");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
pass_count = 1;
|
||||
}
|
||||
|
||||
rd.update_info();
|
||||
if (rd.get_color_type() != traits::get_color_type()
|
||||
|| rd.get_bit_depth() != traits::get_bit_depth())
|
||||
{
|
||||
throw std::logic_error("color type and/or bit depth mismatch"
|
||||
" in png::consumer::read()");
|
||||
}
|
||||
|
||||
this->get_info() = rd.get_image_info();
|
||||
|
||||
pixcon* pixel_con = static_cast< pixcon* >(this);
|
||||
if (pass_count > 1 && !interlacing_supported)
|
||||
{
|
||||
skip_interlaced_rows(rd, pass_count);
|
||||
pass_count = 1;
|
||||
}
|
||||
read_rows(rd, pass_count, pixel_con);
|
||||
|
||||
rd.read_end_info();
|
||||
}
|
||||
|
||||
protected:
|
||||
typedef streaming_base< pixel, info_holder > base;
|
||||
|
||||
/**
|
||||
* \brief Constructs a consumer object using passed image_info
|
||||
* object to store image information.
|
||||
*/
|
||||
explicit consumer(image_info& info)
|
||||
: base(info)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
template< typename istream >
|
||||
void skip_interlaced_rows(reader< istream >& rd, size_t pass_count)
|
||||
{
|
||||
typedef std::vector< pixel > row;
|
||||
typedef row_traits< row > row_traits_type;
|
||||
row dummy_row(this->get_info().get_width());
|
||||
for (size_t pass = 1; pass < pass_count; ++pass)
|
||||
{
|
||||
rd.read_row(reinterpret_cast< byte* >
|
||||
(row_traits_type::get_data(dummy_row)));
|
||||
}
|
||||
}
|
||||
|
||||
template< typename istream >
|
||||
void read_rows(reader< istream >& rd, size_t pass_count,
|
||||
pixcon* pixel_con)
|
||||
{
|
||||
for (size_t pass = 0; pass < pass_count; ++pass)
|
||||
{
|
||||
pixel_con->reset(pass);
|
||||
|
||||
for (size_t pos = 0; pos < this->get_info().get_height(); ++pos)
|
||||
{
|
||||
rd.read_row(pixel_con->get_next_row(pos));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_CONSUMER_HPP_INCLUDED
|
@ -1,338 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_CONVERT_COLOR_SPACE_HPP_INCLUDED
|
||||
#define PNGPP_CONVERT_COLOR_SPACE_HPP_INCLUDED
|
||||
|
||||
#include "error.hpp"
|
||||
#include "rgb_pixel.hpp"
|
||||
#include "rgba_pixel.hpp"
|
||||
#include "gray_pixel.hpp"
|
||||
#include "ga_pixel.hpp"
|
||||
#include "index_pixel.hpp"
|
||||
#include "reader.hpp"
|
||||
#include "writer.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief IO transformation class template. Converts %image %color
|
||||
* space.
|
||||
*/
|
||||
template< typename pixel >
|
||||
struct convert_color_space_impl
|
||||
{
|
||||
typedef pixel_traits< pixel > traits;
|
||||
typedef typename traits::component_type component_type;
|
||||
typedef basic_alpha_pixel_traits< component_type > alpha_traits;
|
||||
|
||||
template< class reader >
|
||||
void operator()(reader& io) const
|
||||
{
|
||||
handle_16(io);
|
||||
handle_alpha(io, alpha_traits::get_alpha_filler());
|
||||
handle_palette(io);
|
||||
handle_rgb(io);
|
||||
handle_gray(io);
|
||||
|
||||
io.set_color_type(traits::get_color_type());
|
||||
io.set_bit_depth(traits::get_bit_depth());
|
||||
}
|
||||
|
||||
protected:
|
||||
static void expand_8_to_16(png_struct*, png_row_info* row_info,
|
||||
byte* row)
|
||||
{
|
||||
#ifdef DEBUG_EXPAND_8_16
|
||||
printf("row: width=%d, bytes=%d, channels=%d\n",
|
||||
row_info->width, row_info->rowbytes, row_info->channels);
|
||||
printf("<= ");
|
||||
dump_row(row, row_info->rowbytes);
|
||||
#endif
|
||||
for (size_t i = row_info->rowbytes; i-- > 0; )
|
||||
{
|
||||
row[2*i + 1] = row[i];
|
||||
row[2*i + 0] = 0;
|
||||
}
|
||||
#ifdef DEBUG_EXPAND_8_16
|
||||
printf("=> ");
|
||||
dump_row(row, 2*row_info->rowbytes);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef DEBUG_EXPAND_8_16
|
||||
static void dump_row(byte const* row, size_t width)
|
||||
{
|
||||
printf("{");
|
||||
for (size_t i = 0; i < width; ++i)
|
||||
{
|
||||
printf(" %02x,", row[i]);
|
||||
}
|
||||
printf(" }\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
template< class reader >
|
||||
static void handle_16(reader& io)
|
||||
{
|
||||
if (io.get_bit_depth() == 16 && traits::get_bit_depth() == 8)
|
||||
{
|
||||
#ifdef PNG_READ_16_TO_8_SUPPORTED
|
||||
io.set_strip_16();
|
||||
#else
|
||||
throw error("expected 8-bit data but found 16-bit;"
|
||||
" recompile with PNG_READ_16_TO_8_SUPPORTED");
|
||||
#endif
|
||||
}
|
||||
if (io.get_bit_depth() != 16 && traits::get_bit_depth() == 16)
|
||||
{
|
||||
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
|
||||
io.set_read_user_transform(expand_8_to_16);
|
||||
io.set_user_transform_info(NULL, 16,
|
||||
traits::get_channels());
|
||||
#else
|
||||
throw error("expected 16-bit data but found 8-bit;"
|
||||
" recompile with"
|
||||
" PNG_READ_USER_TRANSFORM_SUPPORTED");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
template< class reader >
|
||||
static void handle_alpha(reader& io, uint_32 filler)
|
||||
{
|
||||
bool src_alpha = (io.get_color_type() & color_mask_alpha);
|
||||
bool src_tRNS = io.has_chunk(chunk_tRNS);
|
||||
bool dst_alpha = traits::get_color_type() & color_mask_alpha;
|
||||
if ((src_alpha || src_tRNS) && !dst_alpha)
|
||||
{
|
||||
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
|
||||
io.set_strip_alpha();
|
||||
#else
|
||||
throw error("alpha channel unexpected;"
|
||||
" recompile with"
|
||||
" PNG_READ_STRIP_ALPHA_SUPPORTED");
|
||||
#endif
|
||||
}
|
||||
if (!src_alpha && dst_alpha)
|
||||
{
|
||||
#if defined(PNG_tRNS_SUPPORTED) && defined(PNG_READ_EXPAND_SUPPORTED)
|
||||
if (src_tRNS)
|
||||
{
|
||||
io.set_tRNS_to_alpha();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_FILLER_SUPPORTED) && !defined(PNG_1_0_X)
|
||||
io.set_add_alpha(filler, filler_after);
|
||||
#else
|
||||
throw error("expected alpha channel but none found;"
|
||||
" recompile with PNG_READ_FILLER_SUPPORTED"
|
||||
" and be sure to use libpng > 1.0.x");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
template< class reader >
|
||||
static void handle_palette(reader& io)
|
||||
{
|
||||
if (io.get_color_type() == color_type_palette)
|
||||
{
|
||||
#ifdef PNG_READ_EXPAND_SUPPORTED
|
||||
io.set_palette_to_rgb();
|
||||
|
||||
if (traits::get_color_type() != color_type_palette)
|
||||
{
|
||||
io.get_info().drop_palette();
|
||||
}
|
||||
#else
|
||||
throw error("indexed colors unexpected;"
|
||||
" recompile with PNG_READ_EXPAND_SUPPORTED");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
template< class reader >
|
||||
static void handle_rgb(reader& io)
|
||||
{
|
||||
bool src_rgb =
|
||||
io.get_color_type() & (color_mask_rgb | color_mask_palette);
|
||||
bool dst_rgb = traits::get_color_type() & color_mask_rgb;
|
||||
if (src_rgb && !dst_rgb)
|
||||
{
|
||||
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
|
||||
io.set_rgb_to_gray(/*rgb_to_gray_error*/);
|
||||
#else
|
||||
throw error("grayscale data expected;"
|
||||
" recompile with"
|
||||
" PNG_READ_RGB_TO_GRAY_SUPPORTED");
|
||||
#endif
|
||||
}
|
||||
if (!src_rgb && dst_rgb)
|
||||
{
|
||||
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
|
||||
io.set_gray_to_rgb();
|
||||
#else
|
||||
throw error("expected RGB data;"
|
||||
" recompile with"
|
||||
" PNG_READ_GRAY_TO_RGB_SUPPORTED");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
template< class reader >
|
||||
static void handle_gray(reader& io)
|
||||
{
|
||||
if ((io.get_color_type() & ~color_mask_alpha)
|
||||
== color_type_gray)
|
||||
{
|
||||
if (io.get_bit_depth() < 8 && traits::get_bit_depth() >= 8)
|
||||
{
|
||||
#ifdef PNG_READ_EXPAND_SUPPORTED
|
||||
io.set_gray_1_2_4_to_8();
|
||||
#else
|
||||
throw error("convert_color_space: expected 8-bit data;"
|
||||
" recompile with"
|
||||
" PNG_READ_EXPAND_SUPPORTED");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detal
|
||||
|
||||
/**
|
||||
* \brief IO transformation class template. Converts %image %color
|
||||
* space.
|
||||
*
|
||||
* This IO transformation class template is used to convert %color
|
||||
* space of the source %image to the %color space of the target
|
||||
* %image. An error with human-readable description is thrown
|
||||
* when the %color space could not be converted. Often, this
|
||||
* means that you have to recompile libpng with some more
|
||||
* conversion options turned on.
|
||||
*
|
||||
* Not implemented--see specializations.
|
||||
*
|
||||
* \see image, image::read
|
||||
*/
|
||||
template< typename pixel >
|
||||
struct convert_color_space
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Converts %image %color space. A specialization for
|
||||
* rgb_pixel type.
|
||||
*/
|
||||
template<>
|
||||
struct convert_color_space< rgb_pixel >
|
||||
: detail::convert_color_space_impl< rgb_pixel >
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Converts %image %color space. A specialization for
|
||||
* rgb_pixel_16 type.
|
||||
*/
|
||||
template<>
|
||||
struct convert_color_space< rgb_pixel_16 >
|
||||
: detail::convert_color_space_impl< rgb_pixel_16 >
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Converts %image %color space. A specialization for
|
||||
* rgba_pixel type.
|
||||
*/
|
||||
template<>
|
||||
struct convert_color_space< rgba_pixel >
|
||||
: detail::convert_color_space_impl< rgba_pixel >
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Converts %image %color space. A specialization for
|
||||
* rgba_pixel_16 type.
|
||||
*/
|
||||
template<>
|
||||
struct convert_color_space< rgba_pixel_16 >
|
||||
: detail::convert_color_space_impl< rgba_pixel_16 >
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Converts %image %color space. A specialization for
|
||||
* gray_pixel type.
|
||||
*/
|
||||
template<>
|
||||
struct convert_color_space< gray_pixel >
|
||||
: detail::convert_color_space_impl< gray_pixel >
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Converts %image %color space. A specialization for
|
||||
* gray_pixel_16 type.
|
||||
*/
|
||||
template<>
|
||||
struct convert_color_space< gray_pixel_16 >
|
||||
: detail::convert_color_space_impl< gray_pixel_16 >
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Converts %image %color space. A specialization for
|
||||
* ga_pixel type.
|
||||
*/
|
||||
template<>
|
||||
struct convert_color_space< ga_pixel >
|
||||
: detail::convert_color_space_impl< ga_pixel >
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Converts %image %color space. A specialization for
|
||||
* ga_pixel_16 type.
|
||||
*/
|
||||
template<>
|
||||
struct convert_color_space< ga_pixel_16 >
|
||||
: detail::convert_color_space_impl< ga_pixel_16 >
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_CONVERT_COLOR_SPACE_HPP_INCLUDED
|
@ -1,436 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Attribute (.DBF) API</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Attribute (.DBF) API</h1>
|
||||
|
||||
The Attribute (DBF) API uses DBFHandle to represent a handle for access
|
||||
to one .dbf file. The contents of the DBFHandle are visible (see shapefil.h)
|
||||
but should be ignored by the application. It is intended that all information
|
||||
be accessed by API functions. Note that there should be exactly one record
|
||||
in the .dbf file for each shape in the .shp/.shx files. This constraint
|
||||
must be maintained by the application.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFOpen()</h2>
|
||||
|
||||
<pre>
|
||||
DBFHandle DBFOpen( const char * pszDBFFile, const char * pszAccess );
|
||||
|
||||
pszDBFFile: The name of the xBase (.dbf) file to access.
|
||||
|
||||
pszAccess: The fopen() style access string. At this time only
|
||||
"rb" (read-only binary) and "rb+" (read/write binary)
|
||||
should be used.
|
||||
</pre>
|
||||
|
||||
The DBFOpen() function should be used to establish access to an existing
|
||||
xBase format table file. The returned DBFHandle is passed to other
|
||||
access functions, and DBFClose() should be invoked to recover resources, and
|
||||
flush changes to disk when complete. The DBFCreate() function should
|
||||
called to create new xBase files. As a convenience, DBFOpen() can be
|
||||
called with the name of a .shp or .shx file, and it will figure out the
|
||||
name of the related .dbf file.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFCreate()</h2>
|
||||
|
||||
<pre>
|
||||
DBFHandle DBFCreate( const char * pszDBFFile );
|
||||
|
||||
pszDBFFile: The name of the xBase (.dbf) file to create.
|
||||
</pre>
|
||||
|
||||
The DBFCreate() function creates a new xBase format file with the given
|
||||
name, and returns an access handle that can be used with other DBF functions.
|
||||
The newly created file will have no fields, and no records. Fields should
|
||||
be added with DBFAddField() before any records add written.
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFGetFieldCount()</h2>
|
||||
|
||||
<pre>
|
||||
int DBFGetFieldCount( DBFHandle hDBF );
|
||||
|
||||
hDBF: The access handle for the file to be queried, as returned
|
||||
by DBFOpen(), or DBFCreate().
|
||||
</pre>
|
||||
|
||||
The DBFGetFieldCount() function returns the number of fields currently
|
||||
defined for the indicated xBase file.
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFGetRecordCount()</h2>
|
||||
|
||||
<pre>
|
||||
int DBFGetRecordCount( DBFHandle hDBF );
|
||||
|
||||
hDBF: The access handle for the file to be queried, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
</pre>
|
||||
|
||||
The DBFGetRecordCount() function returns the number of records that
|
||||
exist on the xBase file currently. Note that with shape files one xBase
|
||||
record exists for each shape in the .shp/.shx files.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFGetFieldIndex()</h2>
|
||||
|
||||
<pre>
|
||||
int DBFGetFieldIndex( DBFHandle hDBF, const char *pszFieldName );
|
||||
|
||||
hDBF: The access handle for the file to be queried, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
|
||||
pszFieldName: Name of the field to search for.
|
||||
</pre>
|
||||
|
||||
Returns the index of the field matching this name, or -1 on failure. The
|
||||
comparison is case insensitive. However, lengths must match exactly.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFGetFieldInfo()</h2>
|
||||
|
||||
<pre>
|
||||
DBFFieldType DBFGetFieldInfo( DBFHandle hDBF, int iField, char * pszFieldName,
|
||||
int * pnWidth, int * pnDecimals );
|
||||
|
||||
hDBF: The access handle for the file to be queried, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
|
||||
iField: The field to be queried. This should be a number between
|
||||
0 and n-1, where n is the number fields on the file, as
|
||||
returned by DBFGetFieldCount().
|
||||
|
||||
pszFieldName: If this pointer is not NULL the name of the requested field
|
||||
will be written to this location. The pszFieldName buffer
|
||||
should be at least 12 character is size in order to hold
|
||||
the longest possible field name of 11 characters plus a
|
||||
terminating zero character.
|
||||
|
||||
pnWidth: If this pointer is not NULL, the width of the requested field
|
||||
will be returned in the int pointed to by pnWidth. This is
|
||||
the width in characters.
|
||||
|
||||
pnDecimals: If this pointer is not NULL, the number of decimal places
|
||||
precision defined for the field will be returned. This is
|
||||
zero for integer fields, or non-numeric fields.
|
||||
</pre>
|
||||
|
||||
The DBFGetFieldInfo() returns the type of the requested field, which is
|
||||
one of the DBFFieldType enumerated values. As well, the field name, and
|
||||
field width information can optionally be returned. The field type returned
|
||||
does not correspond one to one with the xBase field types. For instance
|
||||
the xBase field type for Date will just be returned as being FTInteger. <p>
|
||||
|
||||
<pre>
|
||||
typedef enum {
|
||||
FTString, /* fixed length string field */
|
||||
FTInteger, /* numeric field with no decimals */
|
||||
FTDouble, /* numeric field with decimals */
|
||||
FTLogical, /* logical field. */
|
||||
FTInvalid /* not a recognised field type */
|
||||
} DBFFieldType;
|
||||
</pre>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFAddField()</h2>
|
||||
|
||||
<pre>
|
||||
int DBFAddField( DBFHandle hDBF, const char * pszFieldName,
|
||||
DBFFieldType eType, int nWidth, int nDecimals );
|
||||
|
||||
hDBF: The access handle for the file to be updated, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
|
||||
pszFieldName: The name of the new field. At most 11 character will be used.
|
||||
In order to use the xBase file in some packages it may be
|
||||
necessary to avoid some special characters in the field names
|
||||
such as spaces, or arithmetic operators.
|
||||
|
||||
eType: One of FTString, FTInteger or FTDouble in order to establish
|
||||
the type of the new field. Note that some valid xBase field
|
||||
types cannot be created such as date fields.
|
||||
|
||||
nWidth: The width of the field to be created. For FTString fields this
|
||||
establishes the maximum length of string that can be stored.
|
||||
For FTInteger this establishes the number of digits of the
|
||||
largest number that can
|
||||
be represented. For FTDouble fields this in combination
|
||||
with the nDecimals value establish the size, and precision
|
||||
of the created field.
|
||||
|
||||
nDecimals: The number of decimal places to reserve for FTDouble fields.
|
||||
For all other field types this should be zero. For instance
|
||||
with nWidth=7, and nDecimals=3 numbers would be formatted
|
||||
similarly to `123.456'.
|
||||
</pre>
|
||||
|
||||
The DBFAddField() function is used to add new fields to an existing xBase
|
||||
file opened with DBFOpen(), or created with DBFCreate(). Note that fields
|
||||
can only be added to xBase files with no records, though this is limitation
|
||||
of this API, not of the file format.<p>
|
||||
|
||||
The DBFAddField() return value is the field number of the new field, or
|
||||
-1 if the addition of the field failed.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFReadIntegerAttribute()</h2>
|
||||
|
||||
<pre>
|
||||
int DBFReadIntegerAttribute( DBFHandle hDBF, int iShape, int iField );
|
||||
|
||||
hDBF: The access handle for the file to be queried, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
|
||||
iShape: The record number (shape number) from which the field value
|
||||
should be read.
|
||||
|
||||
iField: The field within the selected record that should be read.
|
||||
</pre>
|
||||
|
||||
The DBFReadIntegerAttribute() will read the value of one field and return
|
||||
it as an integer. This can be used even with FTString fields, though the
|
||||
returned value will be zero if not interpretable as a number.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFReadDoubleAttribute()</h2>
|
||||
|
||||
<pre>
|
||||
double DBFReadDoubleAttribute( DBFHandle hDBF, int iShape, int iField );
|
||||
|
||||
hDBF: The access handle for the file to be queried, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
|
||||
iShape: The record number (shape number) from which the field value
|
||||
should be read.
|
||||
|
||||
iField: The field within the selected record that should be read.
|
||||
</pre>
|
||||
|
||||
The DBFReadDoubleAttribute() will read the value of one field and return
|
||||
it as a double. This can be used even with FTString fields, though the
|
||||
returned value will be zero if not interpretable as a number.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFReadStringAttribute()</h2>
|
||||
|
||||
<pre>
|
||||
const char *DBFReadStringAttribute( DBFHandle hDBF, int iShape, int iField );
|
||||
|
||||
hDBF: The access handle for the file to be queried, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
|
||||
iShape: The record number (shape number) from which the field value
|
||||
should be read.
|
||||
|
||||
iField: The field within the selected record that should be read.
|
||||
</pre>
|
||||
|
||||
The DBFReadStringAttribute() will read the value of one field and return
|
||||
it as a string. This function may be used on any field type (including
|
||||
FTInteger and FTDouble) and will return the string representation stored
|
||||
in the .dbf file. The returned pointer is to an internal buffer
|
||||
which is only valid untill the next DBF function call. It's contents may
|
||||
be copied with normal string functions such as strcpy(), or strdup(). If
|
||||
the TRIM_DBF_WHITESPACE macro is defined in shapefil.h (it is by default)
|
||||
then all leading and trailing space (ASCII 32) characters will be stripped
|
||||
before the string is returned.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFIsAttributeNULL()</h2>
|
||||
|
||||
<pre>
|
||||
int DBFIsAttributeNULL( DBFHandle hDBF, int iShape, int iField );
|
||||
|
||||
hDBF: The access handle for the file to be queried, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
|
||||
iShape: The record number (shape number) from which the field value
|
||||
should be read.
|
||||
|
||||
iField: The field within the selected record that should be read.
|
||||
</pre>
|
||||
|
||||
This function will return TRUE if the indicated field is NULL valued
|
||||
otherwise FALSE. Note that NULL fields are represented in the .dbf file
|
||||
as having all spaces in the field. Reading NULL fields will result in
|
||||
a value of 0.0 or an empty string with the other DBFRead*Attribute()
|
||||
functions.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFWriteIntegerAttribute</h2>
|
||||
|
||||
<pre>
|
||||
int DBFWriteIntegerAttribute( DBFHandle hDBF, int iShape, int iField,
|
||||
int nFieldValue );
|
||||
|
||||
hDBF: The access handle for the file to be written, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
|
||||
iShape: The record number (shape number) to which the field value
|
||||
should be written.
|
||||
|
||||
iField: The field within the selected record that should be written.
|
||||
|
||||
nFieldValue: The integer value that should be written.
|
||||
</pre>
|
||||
|
||||
The DBFWriteIntegerAttribute() function is used to write a value to a numeric
|
||||
field (FTInteger, or FTDouble). If the write succeeds the value TRUE will
|
||||
be returned, otherwise FALSE will be returned. If the value is too large to
|
||||
fit in the field, it will be truncated and FALSE returned.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFWriteDoubleAttribute()</h2>
|
||||
|
||||
<pre>
|
||||
int DBFWriteDoubleAttribute( DBFHandle hDBF, int iShape, int iField,
|
||||
double dFieldValue );
|
||||
|
||||
hDBF: The access handle for the file to be written, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
|
||||
iShape: The record number (shape number) to which the field value
|
||||
should be written.
|
||||
|
||||
iField: The field within the selected record that should be written.
|
||||
|
||||
dFieldValue: The floating point value that should be written.
|
||||
</pre>
|
||||
|
||||
The DBFWriteDoubleAttribute() function is used to write a value to a numeric
|
||||
field (FTInteger, or FTDouble). If the write succeeds the value TRUE will
|
||||
be returned, otherwise FALSE will be returned. If the value is too large to
|
||||
fit in the field, it will be truncated and FALSE returned.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFWriteStringAttribute()</h2>
|
||||
|
||||
<pre>
|
||||
int DBFWriteStringAttribute( DBFHandle hDBF, int iShape, int iField,
|
||||
const char * pszFieldValue );
|
||||
|
||||
hDBF: The access handle for the file to be written, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
|
||||
iShape: The record number (shape number) to which the field value
|
||||
should be written.
|
||||
|
||||
iField: The field within the selected record that should be written.
|
||||
|
||||
pszFieldValue: The string to be written to the field.
|
||||
</pre>
|
||||
|
||||
The DBFWriteStringAttribute() function is used to write a value to a string
|
||||
field (FString). If the write succeeds the value TRUE willbe returned,
|
||||
otherwise FALSE will be returned. If the value is too large to
|
||||
fit in the field, it will be truncated and FALSE returned.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFWriteNULLAttribute()</h2>
|
||||
|
||||
<pre>
|
||||
int DBFWriteNULLAttribute( DBFHandle hDBF, int iShape, int iField );
|
||||
|
||||
hDBF: The access handle for the file to be written, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
|
||||
iShape: The record number (shape number) to which the field value
|
||||
should be written.
|
||||
|
||||
iField: The field within the selected record that should be written.
|
||||
</pre>
|
||||
|
||||
The DBFWriteNULLAttribute() function is used to clear the indicated field
|
||||
to a NULL value. In the .dbf file this is represented by setting the entire
|
||||
field to spaces. If the write succeeds the value TRUE willbe returned,
|
||||
otherwise FALSE will be returned.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFClose()</h2>
|
||||
|
||||
<pre>
|
||||
void DBFClose( DBFHandle hDBF );
|
||||
|
||||
hDBF: The access handle for the file to be closed.
|
||||
</pre>
|
||||
|
||||
The DBFClose() function will close the indicated xBase file (opened with
|
||||
DBFOpen(), or DBFCreate()), flushing out all information to the file on
|
||||
disk, and recovering any resources associated with having the file open.
|
||||
The file handle (hDBF) should not be used again with the DBF API after
|
||||
calling DBFClose().<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFIsRecordDeleted()</h2>
|
||||
|
||||
<pre>
|
||||
int DBFIsRecordDeleted( DBFHandle hDBF, int iShape );
|
||||
|
||||
hDBF: The access handle for the file to be checked.
|
||||
iShape: The record index to check.
|
||||
</pre>
|
||||
|
||||
Returns TRUE (non-zero) if the record is marked for deletion, otherwise
|
||||
it returns FALSE.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFMarkRecordDeleted()</h2>
|
||||
|
||||
<pre>
|
||||
int DBFMarkRecordDeleted( DBFHandle hDBF, int iShape, int bIsDeleted );
|
||||
|
||||
hDBF: The access handle for the file.
|
||||
iShape: The record index to update.
|
||||
bIsDeleted: TRUE to mark record deleted, or FALSE to undelete it.
|
||||
</pre>
|
||||
|
||||
Returns TRUE on success, or FALSE on error.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFGetNativeFieldType()</h2>
|
||||
|
||||
<pre>
|
||||
char DBFGetNativeFieldType( DBFHandle hDBF, int iField );
|
||||
|
||||
hDBF: The access handle for the file.
|
||||
iField: The field index to query.
|
||||
|
||||
</pre>
|
||||
|
||||
This function returns the DBF type code of the indicated field. It will
|
||||
be one of:<p>
|
||||
|
||||
<ul>
|
||||
<li> 'C' (String)
|
||||
<li> 'D' (Date)
|
||||
<li> 'F' (Float)
|
||||
<li> 'N' (Numeric, with or without decimal)
|
||||
<li> 'L' (Logical)
|
||||
<li> 'M' (Memo: 10 digits .DBT block ptr)
|
||||
<li> ' ' (field out of range)
|
||||
</ul>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_END_INFO_HPP_INCLUDED
|
||||
#define PNGPP_END_INFO_HPP_INCLUDED
|
||||
|
||||
#include "info_base.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Internal class to hold PNG ending %info.
|
||||
*
|
||||
* \see info, info_base
|
||||
*/
|
||||
class end_info
|
||||
: public info_base
|
||||
{
|
||||
public:
|
||||
end_info(io_base& io, png_struct* png)
|
||||
: info_base(io, png)
|
||||
{
|
||||
}
|
||||
|
||||
void destroy()
|
||||
{
|
||||
assert(m_info);
|
||||
png_destroy_info_struct(m_png, & m_info);
|
||||
}
|
||||
|
||||
void read()
|
||||
{
|
||||
png_read_end(m_png, m_info);
|
||||
}
|
||||
|
||||
void write() const
|
||||
{
|
||||
png_write_end(m_png, m_info);
|
||||
}
|
||||
|
||||
// TODO: add methods to read/write text comments etc.
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_END_INFO_HPP_INCLUDED
|
@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_ERROR_HPP_INCLUDED
|
||||
#define PNGPP_ERROR_HPP_INCLUDED
|
||||
|
||||
#include <stdexcept>
|
||||
#include <cerrno>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Exception class to represent runtime errors related to
|
||||
* png++ operation.
|
||||
*/
|
||||
class error
|
||||
: public std::runtime_error
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \param message error description
|
||||
*/
|
||||
explicit error(std::string const& message)
|
||||
: std::runtime_error(message)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Exception class to represent standard library errors
|
||||
* (generally IO).
|
||||
*
|
||||
* \see reader, writer
|
||||
*/
|
||||
class std_error
|
||||
: public std::runtime_error
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructs an std_error object. The \a message string is
|
||||
* appended with <tt>": "</tt> and the error description as
|
||||
* returned by \c strerror(\a error).
|
||||
*
|
||||
* \param message error description
|
||||
* \param error error number
|
||||
*/
|
||||
explicit std_error(std::string const& message, int error = errno)
|
||||
: std::runtime_error((message + ": ") + strerror(error))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_ERROR_HPP_INCLUDED
|
@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_GA_PIXEL_HPP_INCLUDED
|
||||
#define PNGPP_GA_PIXEL_HPP_INCLUDED
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include "types.hpp"
|
||||
#include "pixel_traits.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Basic Gray+Alpha pixel type.
|
||||
*/
|
||||
template< typename T >
|
||||
struct basic_ga_pixel
|
||||
{
|
||||
typedef pixel_traits< basic_ga_pixel< T > > traits;
|
||||
|
||||
/**
|
||||
* \brief Constructs basic_ga_pixel object from \a value and
|
||||
* \a alpha components passed as parameters. Alpha defaults
|
||||
* to full opacity.
|
||||
*/
|
||||
basic_ga_pixel(T value = 0, T alpha = traits::get_alpha_filler())
|
||||
: value(value), alpha(alpha)
|
||||
{
|
||||
}
|
||||
|
||||
T value;
|
||||
T alpha;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The 8-bit Gray+Alpha pixel type.
|
||||
*/
|
||||
typedef basic_ga_pixel< byte > ga_pixel;
|
||||
|
||||
/**
|
||||
* \brief The 16-bit Gray+Alpha pixel type.
|
||||
*/
|
||||
typedef basic_ga_pixel< uint_16 > ga_pixel_16;
|
||||
|
||||
/**
|
||||
* \brief Pixel traits specialization for basic_ga_pixel.
|
||||
*/
|
||||
template< typename T >
|
||||
struct pixel_traits< basic_ga_pixel< T > >
|
||||
: basic_pixel_traits< basic_ga_pixel< T >, T, color_type_ga >,
|
||||
basic_alpha_pixel_traits< T >
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_GA_PIXEL_HPP_INCLUDED
|
@ -1,207 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_GENERATOR_HPP_INCLUDED
|
||||
#define PNGPP_GENERATOR_HPP_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "error.hpp"
|
||||
#include "streaming_base.hpp"
|
||||
#include "writer.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Pixel generator class template.
|
||||
*
|
||||
* Used as a base class for custom pixel generator classes as well
|
||||
* as inside image class implementation to write pixels from the
|
||||
* pixel buffer.
|
||||
*
|
||||
* A usage example can be found in \c example/pixel_generator.cpp.
|
||||
*
|
||||
* Encapsulates PNG %image writing procedure. In order to create
|
||||
* a custom pixel %generator use CRTP trick:
|
||||
*
|
||||
* \code
|
||||
* class pixel_generator
|
||||
* : public png::generator< pixel, pixel_generator >
|
||||
* {
|
||||
* ...
|
||||
* };
|
||||
* \endcode
|
||||
*
|
||||
* Your pixel %generator class should implement \c get_next_row()
|
||||
* method and \c reset() method (optional). Their signatures are
|
||||
* as follows:
|
||||
*
|
||||
* \code
|
||||
* png::byte* get_next_row(size_t pos);
|
||||
* void reset(size_t pass);
|
||||
* \endcode
|
||||
*
|
||||
* The \c get_next_row() method is called every time a new row of
|
||||
* %image data is needed by the writer. The position of the row
|
||||
* being written is passed as \c pos parameter. The \c pos takes
|
||||
* values from \c 0 to \c <image_height>-1 inclusively. The
|
||||
* method should return the starting address of a row buffer
|
||||
* storing an appropriate amount of pixels (i.e. the width of the
|
||||
* %image being written). The address should be casted to
|
||||
* png::byte* pointer type using \c reinterpret_cast<> or a
|
||||
* C-style cast.
|
||||
*
|
||||
* The optional \c reset() method is called every time the new
|
||||
* pass of interlaced %image processing starts. The number of
|
||||
* interlace pass is avaiable as the only parameter of the method.
|
||||
* For non-interlaced images the method is called once prior to
|
||||
* any calls to \c get_next_row(). The value of \c 0 is passed
|
||||
* for the \c pass number. You do not have to implement this
|
||||
* method unless you are going to support interlaced %image
|
||||
* generation.
|
||||
*
|
||||
* An optional template parameter \c info_holder encapsulated
|
||||
* image_info storage policy. Please refer to consumer class
|
||||
* documentation for the detailed description of this parameter.
|
||||
*
|
||||
* An optional \c bool template parameter \c interlacing_supported
|
||||
* specifies whether writing interlacing images is supported by
|
||||
* your %generator class. It defaults to \c false. An attempt to
|
||||
* write an interlaced %image will result in throwing
|
||||
* \c std::logic_error.
|
||||
*
|
||||
* In order to fully support interlacing specify \c true for \c
|
||||
* interlacing_supported parameter and implement \c reset()
|
||||
* method. You _must_ generate the same pixels for every pass to
|
||||
* get the correct PNG %image output.
|
||||
*
|
||||
* \see image, consumer
|
||||
*/
|
||||
template< typename pixel,
|
||||
class pixgen,
|
||||
class info_holder = def_image_info_holder,
|
||||
bool interlacing_supported = false >
|
||||
class generator
|
||||
: public streaming_base< pixel, info_holder >
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief Writes an image to the stream.
|
||||
*
|
||||
* Essentially, this method constructs a writer object and
|
||||
* instructs it to write the image to the stream. It handles
|
||||
* writing interlaced images as long as your generator class
|
||||
* supports this.
|
||||
*/
|
||||
template< typename ostream >
|
||||
void write(ostream& stream)
|
||||
{
|
||||
writer< ostream > wr(stream);
|
||||
wr.set_image_info(this->get_info());
|
||||
wr.write_info();
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
if (pixel_traits< pixel >::get_bit_depth() == 16)
|
||||
{
|
||||
#ifdef PNG_WRITE_SWAP_SUPPORTED
|
||||
wr.set_swap();
|
||||
#else
|
||||
throw error("Cannot write 16-bit image:"
|
||||
" recompile with PNG_WRITE_SWAP_SUPPORTED.");
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t pass_count;
|
||||
if (this->get_info().get_interlace_type() != interlace_none)
|
||||
{
|
||||
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
|
||||
if (interlacing_supported)
|
||||
{
|
||||
pass_count = wr.set_interlace_handling();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::logic_error("Cannot write interlaced image:"
|
||||
" generator does not support it.");
|
||||
}
|
||||
#else
|
||||
throw error("Cannot write interlaced image:"
|
||||
" interlace handling disabled.");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
pass_count = 1;
|
||||
}
|
||||
pixgen* pixel_gen = static_cast< pixgen* >(this);
|
||||
for (size_t pass = 0; pass < pass_count; ++pass)
|
||||
{
|
||||
pixel_gen->reset(pass);
|
||||
|
||||
for (size_t pos = 0; pos < this->get_info().get_height(); ++pos)
|
||||
{
|
||||
wr.write_row(pixel_gen->get_next_row(pos));
|
||||
}
|
||||
}
|
||||
|
||||
wr.write_end_info();
|
||||
}
|
||||
|
||||
protected:
|
||||
typedef streaming_base< pixel, info_holder > base;
|
||||
|
||||
/**
|
||||
* \brief Constructs a generator object using passed image_info
|
||||
* object to store image information.
|
||||
*/
|
||||
explicit generator(image_info& info)
|
||||
: base(info)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Constructs a generator object prepared to generate
|
||||
* an image of specified width and height.
|
||||
*/
|
||||
generator(size_t width, size_t height)
|
||||
: base(width, height)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_GENERATOR_HPP_INCLUDED
|
@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_GRAY_PIXEL_HPP_INCLUDED
|
||||
#define PNGPP_GRAY_PIXEL_HPP_INCLUDED
|
||||
|
||||
#include "types.hpp"
|
||||
#include "packed_pixel.hpp"
|
||||
#include "pixel_traits.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief The 8-bit Grayscale pixel type.
|
||||
*/
|
||||
typedef byte gray_pixel;
|
||||
|
||||
/**
|
||||
* \brief The 16-bit Grayscale pixel type.
|
||||
*/
|
||||
typedef uint_16 gray_pixel_16;
|
||||
|
||||
/**
|
||||
* \brief The packed gray pixel class template. The available
|
||||
* specializations are for 1-, 2- and 4-bit pixels.
|
||||
*/
|
||||
template< size_t bits >
|
||||
class packed_gray_pixel
|
||||
: public packed_pixel< bits >
|
||||
{
|
||||
public:
|
||||
packed_gray_pixel(byte value = 0)
|
||||
: packed_pixel< bits >(value)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The 1-bit Grayscale pixel type.
|
||||
*/
|
||||
typedef packed_gray_pixel< 1 > gray_pixel_1;
|
||||
|
||||
/**
|
||||
* \brief The 2-bit Grayscale pixel type.
|
||||
*/
|
||||
typedef packed_gray_pixel< 2 > gray_pixel_2;
|
||||
|
||||
/**
|
||||
* \brief The 4-bit Grayscale pixel type.
|
||||
*/
|
||||
typedef packed_gray_pixel< 4 > gray_pixel_4;
|
||||
|
||||
/**
|
||||
* \brief Pixel traits specialization for gray_pixel.
|
||||
*/
|
||||
template<>
|
||||
struct pixel_traits< gray_pixel >
|
||||
: basic_pixel_traits< gray_pixel, byte, color_type_gray >
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Pixel traits specialization for gray_pixel_16.
|
||||
*/
|
||||
template<>
|
||||
struct pixel_traits< gray_pixel_16 >
|
||||
: basic_pixel_traits< gray_pixel_16, uint_16, color_type_gray >
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Pixel traits specialization for packed_gray_pixel.
|
||||
*/
|
||||
template< size_t bits >
|
||||
struct pixel_traits< packed_gray_pixel< bits > >
|
||||
: basic_pixel_traits< packed_gray_pixel< bits >, byte,
|
||||
color_type_gray, /* channels = */ 1, bits >
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_GRAY_PIXEL_HPP_INCLUDED
|
@ -1,536 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_IMAGE_HPP_INCLUDED
|
||||
#define PNGPP_IMAGE_HPP_INCLUDED
|
||||
|
||||
#include <fstream>
|
||||
#include "pixel_buffer.hpp"
|
||||
#include "generator.hpp"
|
||||
#include "consumer.hpp"
|
||||
#include "convert_color_space.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Class template to represent PNG image.
|
||||
*
|
||||
* The image consists of pixel data as well as additional %image
|
||||
* %info like interlace type, compression method, palette (for
|
||||
* colormap-based images) etc. Provides methods to read and write
|
||||
* images from/to a generic stream and to manipulate %image pixels.
|
||||
*/
|
||||
template< typename pixel >
|
||||
class image
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief The pixel traits type for \c pixel.
|
||||
*/
|
||||
typedef pixel_traits< pixel > traits;
|
||||
|
||||
/**
|
||||
* \brief The pixel buffer type for \c pixel.
|
||||
*/
|
||||
typedef pixel_buffer< pixel > pixbuf;
|
||||
|
||||
/**
|
||||
* \brief Represents a row of image pixel data.
|
||||
*/
|
||||
typedef typename pixbuf::row_type row_type;
|
||||
|
||||
/**
|
||||
* \brief A transformation functor to convert any image to
|
||||
* appropriate color space.
|
||||
*/
|
||||
typedef convert_color_space< pixel > transform_convert;
|
||||
|
||||
/**
|
||||
* \brief The default io transformation: does nothing.
|
||||
*/
|
||||
struct transform_identity
|
||||
{
|
||||
void operator()(io_base&) const {}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Constructs an empty image.
|
||||
*/
|
||||
image()
|
||||
: m_info(make_image_info< pixel >())
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Constructs an empty image of specified width and height.
|
||||
*/
|
||||
image(size_t width, size_t height)
|
||||
: m_info(make_image_info< pixel >())
|
||||
{
|
||||
resize(width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Constructs an image reading data from specified file
|
||||
* using default converting transform.
|
||||
*/
|
||||
explicit image(std::string const& filename)
|
||||
{
|
||||
read(filename, transform_convert());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Constructs an image reading data from specified file
|
||||
* using custom transformaton.
|
||||
*/
|
||||
template< class transformation >
|
||||
image(std::string const& filename,
|
||||
transformation const& transform)
|
||||
{
|
||||
read(filename.c_str(), transform);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Constructs an image reading data from specified file
|
||||
* using default converting transform.
|
||||
*/
|
||||
explicit image(char const* filename)
|
||||
{
|
||||
read(filename, transform_convert());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Constructs an image reading data from specified file
|
||||
* using custom transformaton.
|
||||
*/
|
||||
template< class transformation >
|
||||
image(char const* filename, transformation const& transform)
|
||||
{
|
||||
read(filename, transform);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Constructs an image reading data from a stream using
|
||||
* default converting transform.
|
||||
*/
|
||||
explicit image(std::istream& stream)
|
||||
{
|
||||
read_stream(stream, transform_convert());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Constructs an image reading data from a stream using
|
||||
* custom transformation.
|
||||
*/
|
||||
template< class transformation >
|
||||
image(std::istream& stream, transformation const& transform)
|
||||
{
|
||||
read_stream(stream, transform);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads an image from specified file using default
|
||||
* converting transform.
|
||||
*/
|
||||
void read(std::string const& filename)
|
||||
{
|
||||
read(filename, transform_convert());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads an image from specified file using custom
|
||||
* transformaton.
|
||||
*/
|
||||
template< class transformation >
|
||||
void read(std::string const& filename, transformation const& transform)
|
||||
{
|
||||
read(filename.c_str(), transform);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads an image from specified file using default
|
||||
* converting transform.
|
||||
*/
|
||||
void read(char const* filename)
|
||||
{
|
||||
read(filename, transform_convert());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads an image from specified file using custom
|
||||
* transformaton.
|
||||
*/
|
||||
template< class transformation >
|
||||
void read(char const* filename, transformation const& transform)
|
||||
{
|
||||
std::ifstream stream(filename, std::ios::binary);
|
||||
if (!stream.is_open())
|
||||
{
|
||||
throw std_error(filename);
|
||||
}
|
||||
stream.exceptions(std::ios::badbit);
|
||||
read_stream(stream, transform);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads an image from a stream using default
|
||||
* converting transform.
|
||||
*/
|
||||
void read(std::istream& stream)
|
||||
{
|
||||
read_stream(stream, transform_convert());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads an image from a stream using custom
|
||||
* transformation.
|
||||
*/
|
||||
template< class transformation >
|
||||
void read(std::istream& stream, transformation const& transform)
|
||||
{
|
||||
read_stream(stream, transform);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads an image from a stream using default
|
||||
* converting transform.
|
||||
*/
|
||||
template< class istream >
|
||||
void read_stream(istream& stream)
|
||||
{
|
||||
read_stream(stream, transform_convert());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads an image from a stream using custom
|
||||
* transformation.
|
||||
*/
|
||||
template< class istream, class transformation >
|
||||
void read_stream(istream& stream, transformation const& transform)
|
||||
{
|
||||
pixel_consumer pixcon(m_info, m_pixbuf);
|
||||
pixcon.read(stream, transform);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Writes an image to specified file.
|
||||
*/
|
||||
void write(std::string const& filename)
|
||||
{
|
||||
write(filename.c_str());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Writes an image to specified file.
|
||||
*/
|
||||
void write(char const* filename)
|
||||
{
|
||||
std::ofstream stream(filename, std::ios::binary);
|
||||
if (!stream.is_open())
|
||||
{
|
||||
throw std_error(filename);
|
||||
}
|
||||
stream.exceptions(std::ios::badbit);
|
||||
write_stream(stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Writes an image to a stream.
|
||||
*/
|
||||
void write_stream(std::ostream& stream)
|
||||
{
|
||||
write_stream(stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Writes an image to a stream.
|
||||
*/
|
||||
template< class ostream >
|
||||
void write_stream(ostream& stream)
|
||||
{
|
||||
pixel_generator pixgen(m_info, m_pixbuf);
|
||||
pixgen.write(stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns a reference to image pixel buffer.
|
||||
*/
|
||||
pixbuf& get_pixbuf()
|
||||
{
|
||||
return m_pixbuf;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns a const reference to image pixel buffer.
|
||||
*/
|
||||
pixbuf const& get_pixbuf() const
|
||||
{
|
||||
return m_pixbuf;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Replaces the image pixel buffer.
|
||||
*
|
||||
* \param buffer a pixel buffer object to take a copy from
|
||||
*/
|
||||
void set_pixbuf(pixbuf const& buffer)
|
||||
{
|
||||
m_pixbuf = buffer;
|
||||
}
|
||||
|
||||
size_t get_width() const
|
||||
{
|
||||
return m_pixbuf.get_width();
|
||||
}
|
||||
|
||||
size_t get_height() const
|
||||
{
|
||||
return m_pixbuf.get_height();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Resizes the image pixel buffer.
|
||||
*/
|
||||
void resize(size_t width, size_t height)
|
||||
{
|
||||
m_pixbuf.resize(width, height);
|
||||
m_info.set_width(width);
|
||||
m_info.set_height(height);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns a reference to the row of image data at
|
||||
* specified index.
|
||||
*
|
||||
* \see pixel_buffer::get_row()
|
||||
*/
|
||||
row_type& get_row(size_t index)
|
||||
{
|
||||
return m_pixbuf.get_row(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns a const reference to the row of image data at
|
||||
* specified index.
|
||||
*
|
||||
* \see pixel_buffer::get_row()
|
||||
*/
|
||||
row_type const& get_row(size_t index) const
|
||||
{
|
||||
return m_pixbuf.get_row(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief The non-checking version of get_row() method.
|
||||
*/
|
||||
row_type& operator[](size_t index)
|
||||
{
|
||||
return m_pixbuf[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief The non-checking version of get_row() method.
|
||||
*/
|
||||
row_type const& operator[](size_t index) const
|
||||
{
|
||||
return m_pixbuf[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns a pixel at (x,y) position.
|
||||
*/
|
||||
pixel get_pixel(size_t x, size_t y) const
|
||||
{
|
||||
return m_pixbuf.get_pixel(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Replaces a pixel at (x,y) position.
|
||||
*/
|
||||
void set_pixel(size_t x, size_t y, pixel p)
|
||||
{
|
||||
m_pixbuf.set_pixel(x, y, p);
|
||||
}
|
||||
|
||||
interlace_type get_interlace_type() const
|
||||
{
|
||||
return m_info.get_interlace_type();
|
||||
}
|
||||
|
||||
void set_interlace_type(interlace_type interlace)
|
||||
{
|
||||
m_info.set_interlace_type(interlace);
|
||||
}
|
||||
|
||||
compression_type get_compression_type() const
|
||||
{
|
||||
return m_info.get_compression_type();
|
||||
}
|
||||
|
||||
void set_compression_type(compression_type compression)
|
||||
{
|
||||
m_info.set_compression_type(compression);
|
||||
}
|
||||
|
||||
filter_type get_filter_type() const
|
||||
{
|
||||
return m_info.get_filter_type();
|
||||
}
|
||||
|
||||
void set_filter_type(filter_type filter)
|
||||
{
|
||||
m_info.set_filter_type(filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns a reference to the image palette.
|
||||
*/
|
||||
palette& get_palette()
|
||||
{
|
||||
return m_info.get_palette();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns a const reference to the image palette.
|
||||
*/
|
||||
palette const& get_palette() const
|
||||
{
|
||||
return m_info.get_palette();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Replaces the image palette.
|
||||
*/
|
||||
void set_palette(palette const& plte)
|
||||
{
|
||||
m_info.set_palette(plte);
|
||||
}
|
||||
|
||||
tRNS const& get_tRNS() const
|
||||
{
|
||||
return m_info.get_tRNS();
|
||||
}
|
||||
|
||||
tRNS& get_tRNS()
|
||||
{
|
||||
return m_info.get_tRNS();
|
||||
}
|
||||
|
||||
void set_tRNS(tRNS const& trns)
|
||||
{
|
||||
m_info.set_tRNS(trns);
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* \brief A common base class template for pixel_consumer and
|
||||
* pixel_generator classes.
|
||||
*/
|
||||
template< typename base_impl >
|
||||
class streaming_impl
|
||||
: public base_impl
|
||||
{
|
||||
public:
|
||||
streaming_impl(image_info& info, pixbuf& pixels)
|
||||
: base_impl(info),
|
||||
m_pixbuf(pixels)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the starting address of a \c pos-th row
|
||||
* in the image's pixel buffer.
|
||||
*/
|
||||
byte* get_next_row(size_t pos)
|
||||
{
|
||||
typedef typename pixbuf::row_traits row_traits;
|
||||
return reinterpret_cast< byte* >
|
||||
(row_traits::get_data(m_pixbuf.get_row(pos)));
|
||||
}
|
||||
|
||||
protected:
|
||||
pixbuf& m_pixbuf;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The pixel buffer adapter for reading pixel data.
|
||||
*/
|
||||
class pixel_consumer
|
||||
: public streaming_impl< consumer< pixel,
|
||||
pixel_consumer,
|
||||
image_info_ref_holder,
|
||||
/* interlacing = */ true > >
|
||||
{
|
||||
public:
|
||||
pixel_consumer(image_info& info, pixbuf& pixels)
|
||||
: streaming_impl< consumer< pixel,
|
||||
pixel_consumer,
|
||||
image_info_ref_holder,
|
||||
true > >(info, pixels)
|
||||
{
|
||||
}
|
||||
|
||||
void reset(size_t pass)
|
||||
{
|
||||
if (pass == 0)
|
||||
{
|
||||
this->m_pixbuf.resize(this->get_info().get_width(),
|
||||
this->get_info().get_height());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The pixel buffer adapter for writing pixel data.
|
||||
*/
|
||||
class pixel_generator
|
||||
: public streaming_impl< generator< pixel,
|
||||
pixel_generator,
|
||||
image_info_ref_holder,
|
||||
/* interlacing = */ true > >
|
||||
{
|
||||
public:
|
||||
pixel_generator(image_info& info, pixbuf& pixels)
|
||||
: streaming_impl< generator< pixel,
|
||||
pixel_generator,
|
||||
image_info_ref_holder,
|
||||
true > >(info, pixels)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
image_info m_info;
|
||||
pixbuf m_pixbuf;
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_IMAGE_HPP_INCLUDED
|
@ -1,203 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_IMAGE_INFO_HPP_INCLUDED
|
||||
#define PNGPP_IMAGE_INFO_HPP_INCLUDED
|
||||
|
||||
#include "types.hpp"
|
||||
#include "palette.hpp"
|
||||
#include "tRNS.hpp"
|
||||
#include "pixel_traits.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Holds information about PNG image.
|
||||
*
|
||||
* \see image, generator, consumer
|
||||
*/
|
||||
class image_info
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief Constructs the image_info object with default values
|
||||
* for color_type, interlace_type, compression_method and
|
||||
* filter_type.
|
||||
*/
|
||||
image_info()
|
||||
: m_width(0),
|
||||
m_height(0),
|
||||
m_bit_depth(0),
|
||||
m_color_type(color_type_none),
|
||||
m_interlace_type(interlace_none),
|
||||
m_compression_type(compression_type_default),
|
||||
m_filter_type(filter_type_default)
|
||||
{
|
||||
}
|
||||
|
||||
size_t get_width() const
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
void set_width(size_t width)
|
||||
{
|
||||
m_width = width;
|
||||
}
|
||||
|
||||
size_t get_height() const
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
void set_height(size_t height)
|
||||
{
|
||||
m_height = height;
|
||||
}
|
||||
|
||||
color_type get_color_type() const
|
||||
{
|
||||
return m_color_type;
|
||||
}
|
||||
|
||||
void set_color_type(color_type color_space)
|
||||
{
|
||||
m_color_type = color_space;
|
||||
}
|
||||
|
||||
size_t get_bit_depth() const
|
||||
{
|
||||
return m_bit_depth;
|
||||
}
|
||||
|
||||
void set_bit_depth(size_t bit_depth)
|
||||
{
|
||||
m_bit_depth = bit_depth;
|
||||
}
|
||||
|
||||
interlace_type get_interlace_type() const
|
||||
{
|
||||
return m_interlace_type;
|
||||
}
|
||||
|
||||
void set_interlace_type(interlace_type interlace)
|
||||
{
|
||||
m_interlace_type = interlace;
|
||||
}
|
||||
|
||||
compression_type get_compression_type() const
|
||||
{
|
||||
return m_compression_type;
|
||||
}
|
||||
|
||||
void set_compression_type(compression_type compression)
|
||||
{
|
||||
m_compression_type = compression;
|
||||
}
|
||||
|
||||
filter_type get_filter_type() const
|
||||
{
|
||||
return m_filter_type;
|
||||
}
|
||||
|
||||
void set_filter_type(filter_type filter)
|
||||
{
|
||||
m_filter_type = filter;
|
||||
}
|
||||
|
||||
palette const& get_palette() const
|
||||
{
|
||||
return m_palette;
|
||||
}
|
||||
|
||||
palette& get_palette()
|
||||
{
|
||||
return m_palette;
|
||||
}
|
||||
|
||||
void set_palette(palette const& plte)
|
||||
{
|
||||
m_palette = plte;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Removes all entries from the palette.
|
||||
*/
|
||||
void drop_palette()
|
||||
{
|
||||
m_palette.clear();
|
||||
}
|
||||
|
||||
tRNS const& get_tRNS() const
|
||||
{
|
||||
return m_tRNS;
|
||||
}
|
||||
|
||||
tRNS& get_tRNS()
|
||||
{
|
||||
return m_tRNS;
|
||||
}
|
||||
|
||||
void set_tRNS(tRNS const& trns)
|
||||
{
|
||||
m_tRNS = trns;
|
||||
}
|
||||
|
||||
protected:
|
||||
uint_32 m_width;
|
||||
uint_32 m_height;
|
||||
size_t m_bit_depth;
|
||||
color_type m_color_type;
|
||||
interlace_type m_interlace_type;
|
||||
compression_type m_compression_type;
|
||||
filter_type m_filter_type;
|
||||
palette m_palette;
|
||||
tRNS m_tRNS;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Returns an image_info object with color_type and
|
||||
* bit_depth fields setup appropriate for the \c pixel type.
|
||||
*/
|
||||
template< typename pixel >
|
||||
image_info
|
||||
make_image_info()
|
||||
{
|
||||
typedef pixel_traits< pixel > traits;
|
||||
image_info info;
|
||||
info.set_color_type(traits::get_color_type());
|
||||
info.set_bit_depth(traits::get_bit_depth());
|
||||
return info;
|
||||
}
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_IMAGE_INFO_HPP_INCLUDED
|
@ -1,112 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_INDEX_PIXEL_HPP_INCLUDED
|
||||
#define PNGPP_INDEX_PIXEL_HPP_INCLUDED
|
||||
|
||||
#include "types.hpp"
|
||||
#include "packed_pixel.hpp"
|
||||
#include "pixel_traits.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief The 8-bit Indexed (colormap) pixel type.
|
||||
*/
|
||||
class index_pixel
|
||||
{
|
||||
public:
|
||||
index_pixel(byte index = 0)
|
||||
: m_index(index)
|
||||
{
|
||||
}
|
||||
|
||||
operator byte() const
|
||||
{
|
||||
return m_index;
|
||||
}
|
||||
|
||||
private:
|
||||
byte m_index;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The packed indexed pixel class template. The available
|
||||
* specializations are for 1-, 2- and 4-bit pixels.
|
||||
*/
|
||||
template< size_t bits >
|
||||
class packed_index_pixel
|
||||
: public packed_pixel< bits >
|
||||
{
|
||||
public:
|
||||
packed_index_pixel(byte value = 0)
|
||||
: packed_pixel< bits >(value)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The 1-bit Indexed pixel type.
|
||||
*/
|
||||
typedef packed_index_pixel< 1 > index_pixel_1;
|
||||
|
||||
/**
|
||||
* \brief The 1-bit Indexed pixel type.
|
||||
*/
|
||||
typedef packed_index_pixel< 2 > index_pixel_2;
|
||||
|
||||
/**
|
||||
* \brief The 1-bit Indexed pixel type.
|
||||
*/
|
||||
typedef packed_index_pixel< 4 > index_pixel_4;
|
||||
|
||||
/**
|
||||
* \brief Pixel traits specialization for index_pixel.
|
||||
*/
|
||||
template<>
|
||||
struct pixel_traits< index_pixel >
|
||||
: basic_pixel_traits< index_pixel, byte, color_type_palette >
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Pixel traits specialization for packed_index_pixel.
|
||||
*/
|
||||
template< size_t bits >
|
||||
struct pixel_traits< packed_index_pixel< bits > >
|
||||
: basic_pixel_traits< packed_index_pixel< bits >, byte,
|
||||
color_type_palette, /* channels = */ 1, bits >
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_INDEX_PIXEL_HPP_INCLUDED
|
@ -1,152 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_INFO_HPP_INCLUDED
|
||||
#define PNGPP_INFO_HPP_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
#include "info_base.hpp"
|
||||
#include "image_info.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Holds information about PNG image. Adapter class for IO
|
||||
* image operations.
|
||||
*/
|
||||
class info
|
||||
: public info_base,
|
||||
public image_info
|
||||
{
|
||||
public:
|
||||
info(io_base& io, png_struct* png)
|
||||
: info_base(io, png)
|
||||
{
|
||||
}
|
||||
|
||||
void read()
|
||||
{
|
||||
assert(m_png);
|
||||
assert(m_info);
|
||||
|
||||
png_read_info(m_png, m_info);
|
||||
png_get_IHDR(m_png,
|
||||
m_info,
|
||||
& m_width,
|
||||
& m_height,
|
||||
reinterpret_cast< int* >(& m_bit_depth),
|
||||
reinterpret_cast< int* >(& m_color_type),
|
||||
reinterpret_cast< int* >(& m_interlace_type),
|
||||
reinterpret_cast< int* >(& m_compression_type),
|
||||
reinterpret_cast< int* >(& m_filter_type));
|
||||
|
||||
if (png_get_valid(m_png, m_info, chunk_PLTE) == chunk_PLTE)
|
||||
{
|
||||
png_color* colors = 0;
|
||||
int count = 0;
|
||||
png_get_PLTE(m_png, m_info, & colors, & count);
|
||||
m_palette.assign(colors, colors + count);
|
||||
}
|
||||
#ifdef PNG_tRNS_SUPPORTED
|
||||
if (png_get_valid(m_png, m_info, chunk_tRNS) == chunk_tRNS)
|
||||
{
|
||||
if (m_color_type == color_type_palette)
|
||||
{
|
||||
int count;
|
||||
byte* values;
|
||||
if (png_get_tRNS(m_png, m_info, & values, & count, NULL)
|
||||
!= PNG_INFO_tRNS)
|
||||
{
|
||||
throw error("png_get_tRNS() failed");
|
||||
}
|
||||
m_tRNS.assign(values, values + count);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void write() const
|
||||
{
|
||||
assert(m_png);
|
||||
assert(m_info);
|
||||
|
||||
sync_ihdr();
|
||||
if (m_color_type == color_type_palette)
|
||||
{
|
||||
if (! m_palette.empty())
|
||||
{
|
||||
png_set_PLTE(m_png, m_info,
|
||||
const_cast< color* >(& m_palette[0]),
|
||||
m_palette.size());
|
||||
}
|
||||
if (! m_tRNS.empty())
|
||||
{
|
||||
#ifdef PNG_tRNS_SUPPORTED
|
||||
png_set_tRNS(m_png, m_info,
|
||||
const_cast< byte* >(& m_tRNS[0]),
|
||||
m_tRNS.size(),
|
||||
NULL);
|
||||
#else
|
||||
throw error("attempted to write tRNS chunk;"
|
||||
" recompile with PNG_tRNS_SUPPORTED");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
png_write_info(m_png, m_info);
|
||||
}
|
||||
|
||||
void update()
|
||||
{
|
||||
assert(m_png);
|
||||
assert(m_info);
|
||||
|
||||
sync_ihdr();
|
||||
png_read_update_info(m_png, m_info);
|
||||
}
|
||||
|
||||
protected:
|
||||
void sync_ihdr(void) const
|
||||
{
|
||||
png_set_IHDR(m_png,
|
||||
m_info,
|
||||
m_width,
|
||||
m_height,
|
||||
m_bit_depth,
|
||||
m_color_type,
|
||||
m_interlace_type,
|
||||
m_compression_type,
|
||||
m_filter_type);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_INFO_HPP_INCLUDED
|
@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_INFO_BASE_HPP_INCLUDED
|
||||
#define PNGPP_INFO_BASE_HPP_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
#include "error.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
class io_base;
|
||||
|
||||
/**
|
||||
* \brief Internal class to hold PNG info or end_info.
|
||||
*/
|
||||
class info_base
|
||||
{
|
||||
info_base(info_base const&);
|
||||
info_base& operator=(info_base const&);
|
||||
|
||||
public:
|
||||
info_base(io_base& io, png_struct* png)
|
||||
: m_io(io),
|
||||
m_png(png),
|
||||
m_info(png_create_info_struct(m_png))
|
||||
{
|
||||
}
|
||||
|
||||
png_info* get_png_info() const
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
|
||||
png_info** get_png_info_ptr()
|
||||
{
|
||||
return & m_info;
|
||||
}
|
||||
|
||||
protected:
|
||||
io_base& m_io;
|
||||
png_struct* m_png;
|
||||
png_info* m_info;
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_INFO_BASE_HPP_INCLUDED
|
@ -1,468 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_IO_BASE_HPP_INCLUDED
|
||||
#define PNGPP_IO_BASE_HPP_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdarg>
|
||||
#include "error.hpp"
|
||||
#include "info.hpp"
|
||||
#include "end_info.hpp"
|
||||
|
||||
static void
|
||||
trace_io_transform(char const* fmt, ...)
|
||||
{
|
||||
#ifdef DEBUG_IO_TRANSFORM
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
fprintf(stderr, "TRANSFORM_IO: ");
|
||||
vfprintf(stderr, fmt, va);
|
||||
va_end(va);
|
||||
#endif
|
||||
}
|
||||
#define TRACE_IO_TRANSFORM trace_io_transform
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Base class for PNG reader/writer classes.
|
||||
*
|
||||
* \see reader, writer
|
||||
*/
|
||||
class io_base
|
||||
{
|
||||
io_base(io_base const&);
|
||||
io_base& operator=(io_base const&);
|
||||
|
||||
public:
|
||||
explicit io_base(png_struct* png)
|
||||
: m_png(png),
|
||||
m_info(*this, m_png),
|
||||
m_end_info(*this, m_png)
|
||||
{
|
||||
}
|
||||
|
||||
~io_base()
|
||||
{
|
||||
assert(! m_png);
|
||||
assert(! m_info.get_png_info());
|
||||
assert(! m_end_info.get_png_info());
|
||||
}
|
||||
|
||||
png_struct* get_png_struct() const
|
||||
{
|
||||
return m_png;
|
||||
}
|
||||
|
||||
info& get_info()
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
|
||||
info const& get_info() const
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
|
||||
image_info const& get_image_info() const
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
|
||||
void set_image_info(image_info const& info)
|
||||
{
|
||||
static_cast< image_info& >(m_info) = info; // slice it
|
||||
}
|
||||
|
||||
end_info& get_end_info()
|
||||
{
|
||||
return m_end_info;
|
||||
}
|
||||
|
||||
end_info const& get_end_info() const
|
||||
{
|
||||
return m_end_info;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// info accessors
|
||||
//
|
||||
size_t get_width() const
|
||||
{
|
||||
return m_info.get_width();
|
||||
}
|
||||
|
||||
void set_width(size_t width)
|
||||
{
|
||||
m_info.set_width(width);
|
||||
}
|
||||
|
||||
size_t get_height() const
|
||||
{
|
||||
return m_info.get_height();
|
||||
}
|
||||
|
||||
void set_height(size_t height)
|
||||
{
|
||||
m_info.set_height(height);
|
||||
}
|
||||
|
||||
color_type get_color_type() const
|
||||
{
|
||||
return m_info.get_color_type();
|
||||
}
|
||||
|
||||
void set_color_type(color_type color_space)
|
||||
{
|
||||
m_info.set_color_type(color_space);
|
||||
}
|
||||
|
||||
size_t get_bit_depth() const
|
||||
{
|
||||
return m_info.get_bit_depth();
|
||||
}
|
||||
|
||||
void set_bit_depth(size_t bit_depth)
|
||||
{
|
||||
m_info.set_bit_depth(bit_depth);
|
||||
}
|
||||
|
||||
interlace_type get_interlace_type() const
|
||||
{
|
||||
return m_info.get_interlace_type();
|
||||
}
|
||||
|
||||
void set_interlace_type(interlace_type interlace)
|
||||
{
|
||||
m_info.set_interlace_type(interlace);
|
||||
}
|
||||
|
||||
compression_type get_compression_type() const
|
||||
{
|
||||
return m_info.get_compression_type();
|
||||
}
|
||||
|
||||
void set_compression_type(compression_type compression)
|
||||
{
|
||||
m_info.set_compression_type(compression);
|
||||
}
|
||||
|
||||
filter_type get_filter_type() const
|
||||
{
|
||||
return m_info.get_filter_type();
|
||||
}
|
||||
|
||||
void set_filter_type(filter_type filter)
|
||||
{
|
||||
m_info.set_filter_type(filter);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool has_chunk(chunk id)
|
||||
{
|
||||
return png_get_valid(m_png,
|
||||
m_info.get_png_info(),
|
||||
uint_32(id)) == uint_32(id);
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_EXPAND_SUPPORTED)
|
||||
void set_gray_1_2_4_to_8() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_expand_gray_1_2_4_to_8\n");
|
||||
png_set_expand_gray_1_2_4_to_8(m_png);
|
||||
}
|
||||
|
||||
void set_palette_to_rgb() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_palette_to_rgb\n");
|
||||
png_set_palette_to_rgb(m_png);
|
||||
}
|
||||
|
||||
void set_tRNS_to_alpha() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_tRNS_to_alpha\n");
|
||||
png_set_tRNS_to_alpha(m_png);
|
||||
}
|
||||
#endif // defined(PNG_READ_EXPAND_SUPPORTED)
|
||||
|
||||
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
|
||||
void set_bgr() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_bgr\n");
|
||||
png_set_bgr(m_png);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
|
||||
void set_gray_to_rgb() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_gray_to_rgb\n");
|
||||
png_set_gray_to_rgb(m_png);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
void set_rgb_to_gray(rgb_to_gray_error_action error_action
|
||||
= rgb_to_gray_silent,
|
||||
double red_weight = -1.0,
|
||||
double green_weight = -1.0) const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_rgb_to_gray: error_action=%d,"
|
||||
" red_weight=%lf, green_weight=%lf\n",
|
||||
error_action, red_weight, green_weight);
|
||||
|
||||
png_set_rgb_to_gray(m_png, error_action, red_weight, green_weight);
|
||||
}
|
||||
#else
|
||||
void set_rgb_to_gray(rgb_to_gray_error_action error_action
|
||||
= rgb_to_gray_silent,
|
||||
fixed_point red_weight = -1,
|
||||
fixed_point green_weight = -1) const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_rgb_to_gray_fixed: error_action=%d,"
|
||||
" red_weight=%d, green_weight=%d\n",
|
||||
error_action, red_weight, green_weight);
|
||||
|
||||
png_set_rgb_to_gray_fixed(m_png, error_action,
|
||||
red_weight, green_weight);
|
||||
}
|
||||
#endif // PNG_FLOATING_POINT_SUPPORTED
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// alpha channel transformations
|
||||
//
|
||||
#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
|
||||
void set_strip_alpha() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_strip_alpha\n");
|
||||
png_set_strip_alpha(m_png);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) \
|
||||
|| defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
|
||||
void set_swap_alpha() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_swap_alpha\n");
|
||||
png_set_swap_alpha(m_png);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) \
|
||||
|| defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
|
||||
void set_invert_alpha() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_invert_alpha\n");
|
||||
png_set_invert_alpha(m_png);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
|
||||
void set_filler(uint_32 filler, filler_type type) const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_filler: filler=%08x, type=%d\n",
|
||||
filler, type);
|
||||
|
||||
png_set_filler(m_png, filler, type);
|
||||
}
|
||||
|
||||
#if !defined(PNG_1_0_X)
|
||||
void set_add_alpha(uint_32 filler, filler_type type) const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_add_alpha: filler=%08x, type=%d\n",
|
||||
filler, type);
|
||||
|
||||
png_set_add_alpha(m_png, filler, type);
|
||||
}
|
||||
#endif
|
||||
#endif // PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED
|
||||
|
||||
#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
|
||||
void set_swap() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_swap\n");
|
||||
png_set_swap(m_png);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
void set_packing() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_packing\n");
|
||||
png_set_packing(m_png);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_PACKSWAP_SUPPORTED) \
|
||||
|| defined(PNG_WRITE_PACKSWAP_SUPPORTED)
|
||||
void set_packswap() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_packswap\n");
|
||||
png_set_packswap(m_png);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||
void set_shift(byte red_bits, byte green_bits, byte blue_bits,
|
||||
byte alpha_bits = 0) const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_shift: red_bits=%d, green_bits=%d,"
|
||||
" blue_bits=%d, alpha_bits=%d\n",
|
||||
red_bits, green_bits, blue_bits, alpha_bits);
|
||||
|
||||
if (get_color_type() != color_type_rgb
|
||||
|| get_color_type() != color_type_rgb_alpha)
|
||||
{
|
||||
throw error("set_shift: expected RGB or RGBA color type");
|
||||
}
|
||||
color_info bits;
|
||||
bits.red = red_bits;
|
||||
bits.green = green_bits;
|
||||
bits.blue = blue_bits;
|
||||
bits.alpha = alpha_bits;
|
||||
png_set_shift(m_png, & bits);
|
||||
}
|
||||
|
||||
void set_shift(byte gray_bits, byte alpha_bits = 0) const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_shift: gray_bits=%d, alpha_bits=%d\n",
|
||||
gray_bits, alpha_bits);
|
||||
|
||||
if (get_color_type() != color_type_gray
|
||||
|| get_color_type() != color_type_gray_alpha)
|
||||
{
|
||||
throw error("set_shift: expected Gray or Gray+Alpha"
|
||||
" color type");
|
||||
}
|
||||
color_info bits;
|
||||
bits.gray = gray_bits;
|
||||
bits.alpha = alpha_bits;
|
||||
png_set_shift(m_png, & bits);
|
||||
}
|
||||
#endif // PNG_READ_SHIFT_SUPPORTED || PNG_WRITE_SHIFT_SUPPORTED
|
||||
|
||||
#if defined(PNG_READ_INTERLACING_SUPPORTED) \
|
||||
|| defined(PNG_WRITE_INTERLACING_SUPPORTED)
|
||||
int set_interlace_handling() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_interlace_handling\n");
|
||||
return png_set_interlace_handling(m_png);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
|
||||
void set_invert_mono() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_invert_mono\n");
|
||||
png_set_invert_mono(m_png);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_16_TO_8_SUPPORTED)
|
||||
void set_strip_16() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_strip_16\n");
|
||||
png_set_strip_16(m_png);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
|
||||
void set_read_user_transform(png_user_transform_ptr transform_fn)
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_read_user_transform_fn\n");
|
||||
png_set_read_user_transform_fn(m_png, transform_fn);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) \
|
||||
|| defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
void set_user_transform_info(void* info, int bit_depth, int channels)
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_user_transform_info: bit_depth=%d,"
|
||||
" channels=%d\n", bit_depth, channels);
|
||||
|
||||
png_set_user_transform_info(m_png, info, bit_depth, channels);
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
void* get_io_ptr() const
|
||||
{
|
||||
return png_get_io_ptr(m_png);
|
||||
}
|
||||
|
||||
void set_error(char const* message)
|
||||
{
|
||||
assert(message);
|
||||
m_error = message;
|
||||
}
|
||||
|
||||
void reset_error()
|
||||
{
|
||||
m_error.clear();
|
||||
}
|
||||
|
||||
/*
|
||||
std::string const& get_error() const
|
||||
{
|
||||
return m_error;
|
||||
}
|
||||
*/
|
||||
|
||||
bool is_error() const
|
||||
{
|
||||
return !m_error.empty();
|
||||
}
|
||||
|
||||
void raise_error()
|
||||
{
|
||||
longjmp(png_jmpbuf(m_png), -1);
|
||||
}
|
||||
|
||||
static void raise_error(png_struct* png, char const* message)
|
||||
{
|
||||
io_base* io = static_cast< io_base* >(png_get_error_ptr(png));
|
||||
io->set_error(message);
|
||||
io->raise_error();
|
||||
}
|
||||
|
||||
png_struct* m_png;
|
||||
info m_info;
|
||||
end_info m_end_info;
|
||||
std::string m_error;
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_IO_BASE_HPP_INCLUDED
|
@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_PACKED_PIXEL_HPP_INCLUDED
|
||||
#define PNGPP_PACKED_PIXEL_HPP_INCLUDED
|
||||
|
||||
#include "types.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template< size_t bits > class allowed_bit_depth;
|
||||
|
||||
template<> class allowed_bit_depth< 1 > {};
|
||||
template<> class allowed_bit_depth< 2 > {};
|
||||
template<> class allowed_bit_depth< 4 > {};
|
||||
} // namespace detail
|
||||
|
||||
/**
|
||||
* \brief The packed pixel class template.
|
||||
*
|
||||
* \see packed_gray_pixel, packed_index_pixel
|
||||
*/
|
||||
template< size_t bits >
|
||||
class packed_pixel
|
||||
: detail::allowed_bit_depth< bits >
|
||||
{
|
||||
public:
|
||||
packed_pixel(byte value = 0)
|
||||
: m_value(value & get_bit_mask())
|
||||
{
|
||||
}
|
||||
|
||||
operator byte() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
static size_t const get_bit_depth()
|
||||
{
|
||||
return bits;
|
||||
}
|
||||
|
||||
static byte const get_bit_mask()
|
||||
{
|
||||
return (1 << bits) - 1;
|
||||
}
|
||||
|
||||
private:
|
||||
byte m_value;
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_PACKED_PIXEL_HPP_INCLUDED
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_PALETTE_HPP_INCLUDED
|
||||
#define PNGPP_PALETTE_HPP_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
#include "color.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief The palette type. Currently implemented as \c std::vector
|
||||
* of png::color.
|
||||
*/
|
||||
typedef std::vector< color > palette;
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_PALETTE_HPP_INCLUDED
|
@ -1,495 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_PIXEL_BUFFER_HPP_INCLUDED
|
||||
#define PNGPP_PIXEL_BUFFER_HPP_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
#include "packed_pixel.hpp"
|
||||
#include "gray_pixel.hpp"
|
||||
#include "index_pixel.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief The pixel row traits class template. Provides a common
|
||||
* way to get starting address of the row for packed and unpacked
|
||||
* row types.
|
||||
*
|
||||
* Not implemented--see specializations.
|
||||
*/
|
||||
template< typename row > class row_traits;
|
||||
|
||||
/**
|
||||
* \brief The basic class template to represent image pixel data.
|
||||
*/
|
||||
template< typename pixel,
|
||||
typename row,
|
||||
class traits = row_traits< row > >
|
||||
class basic_pixel_buffer
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief A row of pixel data.
|
||||
*/
|
||||
typedef row row_type;
|
||||
typedef traits row_traits;
|
||||
|
||||
/**
|
||||
* \brief Constructs an empty 0x0 pixel buffer object.
|
||||
*/
|
||||
basic_pixel_buffer()
|
||||
: m_width(0),
|
||||
m_height(0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Constructs an empty pixel buffer object.
|
||||
*/
|
||||
basic_pixel_buffer(size_t width, size_t height)
|
||||
: m_width(0),
|
||||
m_height(0)
|
||||
{
|
||||
resize(width, height);
|
||||
}
|
||||
|
||||
size_t get_width() const
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
size_t get_height() const
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Resizes the pixel buffer.
|
||||
*
|
||||
* If new width or height is greater than the original,
|
||||
* expanded pixels are filled with value of \a pixel().
|
||||
*/
|
||||
void resize(size_t width, size_t height)
|
||||
{
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
m_rows.resize(height);
|
||||
for (typename row_vec::iterator r = m_rows.begin();
|
||||
r != m_rows.end();
|
||||
++r)
|
||||
{
|
||||
r->resize(width);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns a reference to the row of image data at
|
||||
* specified index.
|
||||
*
|
||||
* Checks the index before returning a row: an instance of
|
||||
* std::out_of_range is thrown if \c index is greater than \c
|
||||
* height.
|
||||
*/
|
||||
row_type& get_row(size_t index)
|
||||
{
|
||||
return m_rows.at(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns a const reference to the row of image data at
|
||||
* specified index.
|
||||
*
|
||||
* The checking version.
|
||||
*/
|
||||
row_type const& get_row(size_t index) const
|
||||
{
|
||||
return m_rows.at(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief The non-checking version of get_row() method.
|
||||
*/
|
||||
row_type& operator[](size_t index)
|
||||
{
|
||||
return m_rows[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief The non-checking version of get_row() method.
|
||||
*/
|
||||
row_type const& operator[](size_t index) const
|
||||
{
|
||||
return m_rows[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Replaces the row at specified index.
|
||||
*/
|
||||
void put_row(size_t index, row_type const& r)
|
||||
{
|
||||
assert(r.size() == m_width);
|
||||
m_rows.at(index) = r;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns a pixel at (x,y) position.
|
||||
*/
|
||||
pixel get_pixel(size_t x, size_t y) const
|
||||
{
|
||||
return get_row(y).at(x);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Replaces a pixel at (x,y) position.
|
||||
*/
|
||||
void set_pixel(size_t x, size_t y, pixel p)
|
||||
{
|
||||
get_row(y).at(x) = p;
|
||||
}
|
||||
|
||||
protected:
|
||||
size_t m_width;
|
||||
size_t m_height;
|
||||
typedef std::vector< row_type > row_vec;
|
||||
row_vec m_rows;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The row_traits specialization for unpacked pixel rows.
|
||||
*/
|
||||
template< typename pixel >
|
||||
class row_traits< std::vector< pixel > >
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief Returns the starting address of the row.
|
||||
*/
|
||||
static pixel* get_data(std::vector< pixel >& vec)
|
||||
{
|
||||
assert(vec.size());
|
||||
return & vec[0];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The pixel_buffer specialization for unpacked pixels.
|
||||
*/
|
||||
template< typename pixel >
|
||||
class pixel_buffer
|
||||
: public basic_pixel_buffer< pixel, std::vector< pixel > >
|
||||
{
|
||||
public:
|
||||
pixel_buffer()
|
||||
{
|
||||
}
|
||||
|
||||
pixel_buffer(size_t width, size_t height)
|
||||
: basic_pixel_buffer< pixel, std::vector< pixel > >(width, height)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template< class pixel, typename reference >
|
||||
class basic_packed_pixel_proxy
|
||||
{
|
||||
public:
|
||||
explicit basic_packed_pixel_proxy(reference ref)
|
||||
: m_ref(ref),
|
||||
m_shift(0)
|
||||
{
|
||||
}
|
||||
|
||||
basic_packed_pixel_proxy(reference ref, size_t index)
|
||||
: m_ref(ref),
|
||||
m_shift(get_shift(index))
|
||||
{
|
||||
}
|
||||
|
||||
operator pixel() const
|
||||
{
|
||||
return pixel((m_ref >> m_shift) & pixel::get_bit_mask());
|
||||
}
|
||||
|
||||
protected:
|
||||
/*
|
||||
* bits: . . .
|
||||
* 1: 7 6 5 4 3 2 1 0
|
||||
* 2: 6 4 2 0
|
||||
* 4: 4 0
|
||||
*/
|
||||
static size_t get_shift(size_t index)
|
||||
{
|
||||
size_t const bits = pixel::get_bit_depth();
|
||||
return (8 - bits) - (index % get_pixels_per_byte()) * bits;
|
||||
}
|
||||
|
||||
static size_t get_pixels_per_byte()
|
||||
{
|
||||
return 8 / pixel::get_bit_depth();
|
||||
}
|
||||
|
||||
reference m_ref;
|
||||
size_t m_shift;
|
||||
};
|
||||
|
||||
template< class pixel >
|
||||
class const_packed_pixel_proxy
|
||||
: public basic_packed_pixel_proxy< pixel, byte const& >
|
||||
{
|
||||
public:
|
||||
const_packed_pixel_proxy(byte const& ref, size_t index)
|
||||
: basic_packed_pixel_proxy< pixel, byte const& >(ref, index)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template< class pixel >
|
||||
class packed_pixel_proxy
|
||||
: public basic_packed_pixel_proxy< pixel, byte& >
|
||||
{
|
||||
public:
|
||||
typedef basic_packed_pixel_proxy< pixel, byte& > basic_proxy;
|
||||
|
||||
packed_pixel_proxy(byte& ref, size_t index)
|
||||
: basic_proxy(ref, index)
|
||||
{
|
||||
}
|
||||
|
||||
packed_pixel_proxy(packed_pixel_proxy const& other)
|
||||
: basic_proxy(other.m_ref)
|
||||
{
|
||||
this->m_shift = other.m_shift;
|
||||
}
|
||||
|
||||
packed_pixel_proxy& operator=(packed_pixel_proxy const& other)
|
||||
{
|
||||
return *this = static_cast< pixel >(other);
|
||||
}
|
||||
|
||||
template< typename reference >
|
||||
packed_pixel_proxy&
|
||||
operator=(basic_packed_pixel_proxy< pixel, reference > const& other)
|
||||
{
|
||||
return *this = static_cast< pixel >(other);
|
||||
}
|
||||
|
||||
packed_pixel_proxy& operator=(pixel p)
|
||||
{
|
||||
this->m_ref = (this->m_ref
|
||||
& ~(pixel::get_bit_mask() << this->m_shift))
|
||||
| (p << this->m_shift);
|
||||
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/**
|
||||
* \brief The packed pixel row class template.
|
||||
*
|
||||
* Stores the pixel row as a std::vector of byte-s, providing
|
||||
* access to individual packed pixels via proxy objects.
|
||||
*/
|
||||
template< class pixel >
|
||||
class packed_pixel_row
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief Constructs a pixel row object for \c size packed pixels.
|
||||
*/
|
||||
explicit packed_pixel_row(size_t size = 0)
|
||||
{
|
||||
resize(size);
|
||||
}
|
||||
|
||||
size_t size() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Resizes the pixel row to hold up to \c size packed pixels.
|
||||
*/
|
||||
void resize(size_t size)
|
||||
{
|
||||
m_vec.resize(size / get_pixels_per_byte()
|
||||
+ (size % get_pixels_per_byte() ? 1 : 0));
|
||||
m_size = size;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief The immutable packed pixel proxy type.
|
||||
*/
|
||||
typedef detail::const_packed_pixel_proxy< pixel > const_pixel_proxy;
|
||||
|
||||
/**
|
||||
* \brief The mutable packed pixel proxy type.
|
||||
*/
|
||||
typedef detail::packed_pixel_proxy< pixel > pixel_proxy;
|
||||
|
||||
/**
|
||||
* \brief Returns an immutable proxy the to the pixel at \c
|
||||
* index.
|
||||
*/
|
||||
const_pixel_proxy at(size_t index) const
|
||||
{
|
||||
return const_pixel_proxy(m_vec.at(index / get_pixels_per_byte()),
|
||||
index);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns a mutable proxy the to the pixel at \c
|
||||
* index.
|
||||
*/
|
||||
pixel_proxy at(size_t index)
|
||||
{
|
||||
return pixel_proxy(m_vec.at(index / get_pixels_per_byte()),
|
||||
index);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns an immutable proxy the to the pixel at \c
|
||||
* index. The non-checking version.
|
||||
*/
|
||||
const_pixel_proxy operator[](size_t index) const
|
||||
{
|
||||
return const_pixel_proxy(m_vec[index / get_pixels_per_byte()],
|
||||
index);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns n mutable proxy the to the pixel at \c
|
||||
* index. The non-checking version.
|
||||
*/
|
||||
pixel_proxy operator[](size_t index)
|
||||
{
|
||||
return pixel_proxy(m_vec[index / get_pixels_per_byte()],
|
||||
index);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the starting address of the row.
|
||||
*/
|
||||
byte* get_data()
|
||||
{
|
||||
assert(m_vec.size());
|
||||
return & m_vec[0];
|
||||
}
|
||||
|
||||
private:
|
||||
static size_t get_pixels_per_byte()
|
||||
{
|
||||
return 8 / pixel::get_bit_depth();
|
||||
}
|
||||
|
||||
std::vector< byte > m_vec;
|
||||
size_t m_size;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The row_traits class template specialization for packed
|
||||
* pixel row type.
|
||||
*/
|
||||
template< typename pixel >
|
||||
class row_traits< packed_pixel_row< pixel > >
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief Returns the starting address of the row.
|
||||
*/
|
||||
static byte* get_data(packed_pixel_row< pixel >& row)
|
||||
{
|
||||
return row.get_data();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The pixel buffer class template specialization for the
|
||||
* packed_gray_pixel type.
|
||||
*/
|
||||
template< size_t bits >
|
||||
class pixel_buffer< packed_gray_pixel< bits > >
|
||||
: public basic_pixel_buffer< packed_gray_pixel< bits >,
|
||||
packed_pixel_row< packed_gray_pixel
|
||||
< bits > > >
|
||||
{
|
||||
public:
|
||||
typedef packed_gray_pixel< bits > pixel_type;
|
||||
typedef packed_pixel_row< pixel_type > pixel_row_type;
|
||||
|
||||
pixel_buffer()
|
||||
{
|
||||
}
|
||||
|
||||
pixel_buffer(size_t width, size_t height)
|
||||
: basic_pixel_buffer< pixel_type,
|
||||
pixel_row_type >(width, height)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The pixel buffer class template specialization for the
|
||||
* packed_index_pixel type.
|
||||
*/
|
||||
template< size_t bits >
|
||||
class pixel_buffer< packed_index_pixel< bits > >
|
||||
: public basic_pixel_buffer< packed_index_pixel< bits >,
|
||||
packed_pixel_row< packed_index_pixel
|
||||
< bits > > >
|
||||
{
|
||||
public:
|
||||
typedef packed_index_pixel< bits > pixel_type;
|
||||
typedef packed_pixel_row< pixel_type > pixel_row_type;
|
||||
|
||||
pixel_buffer()
|
||||
{
|
||||
}
|
||||
|
||||
pixel_buffer(size_t width, size_t height)
|
||||
: basic_pixel_buffer< pixel_type,
|
||||
pixel_row_type >(width, height)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_PIXEL_BUFFER_HPP_INCLUDED
|
@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_PIXEL_TRAITS_HPP_INCLUDED
|
||||
#define PNGPP_PIXEL_TRAITS_HPP_INCLUDED
|
||||
|
||||
#include <limits>
|
||||
#include "types.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Pixel traits class template.
|
||||
*
|
||||
* Provides information about pixel color type and components bit depth.
|
||||
* Not implemented--see specializations.
|
||||
*
|
||||
* \see pixel_traits<rgb_pixel>, pixel_traits<rgba_pixel>
|
||||
*/
|
||||
template< typename pixel > struct pixel_traits;
|
||||
|
||||
/**
|
||||
* \brief Basic pixel traits class template.
|
||||
*
|
||||
* Provides common implementation for various pixel_traits<>
|
||||
* specializations.
|
||||
*/
|
||||
template< typename pixel,
|
||||
typename component,
|
||||
color_type pixel_color_type,
|
||||
size_t channels = sizeof(pixel) / sizeof(component),
|
||||
size_t bit_depth = std::numeric_limits< component >::digits >
|
||||
struct basic_pixel_traits
|
||||
{
|
||||
typedef pixel pixel_type;
|
||||
typedef component component_type;
|
||||
|
||||
static color_type get_color_type()
|
||||
{
|
||||
return pixel_color_type;
|
||||
}
|
||||
static size_t get_channels()
|
||||
{
|
||||
return channels;
|
||||
}
|
||||
static size_t get_bit_depth()
|
||||
{
|
||||
return bit_depth;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Basic pixel traits class template for pixels with alpha
|
||||
* channel.
|
||||
*/
|
||||
template< typename component >
|
||||
struct basic_alpha_pixel_traits
|
||||
{
|
||||
/**
|
||||
* \brief Returns the default alpha channel filler for full
|
||||
* opacity.
|
||||
*/
|
||||
static component get_alpha_filler()
|
||||
{
|
||||
return std::numeric_limits< component >::max();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_PIXEL_TRAITS_HPP_INCLUDED
|
@ -1,295 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_PNG_HPP_INCLUDED
|
||||
#define PNGPP_PNG_HPP_INCLUDED
|
||||
|
||||
#include <png.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "types.hpp"
|
||||
#include "error.hpp"
|
||||
#include "color.hpp"
|
||||
#include "palette.hpp"
|
||||
#include "tRNS.hpp"
|
||||
#include "packed_pixel.hpp"
|
||||
#include "rgb_pixel.hpp"
|
||||
#include "rgba_pixel.hpp"
|
||||
#include "gray_pixel.hpp"
|
||||
#include "ga_pixel.hpp"
|
||||
#include "index_pixel.hpp"
|
||||
#include "info_base.hpp"
|
||||
#include "info.hpp"
|
||||
#include "end_info.hpp"
|
||||
#include "io_base.hpp"
|
||||
#include "reader.hpp"
|
||||
#include "writer.hpp"
|
||||
#include "generator.hpp"
|
||||
#include "consumer.hpp"
|
||||
#include "pixel_buffer.hpp"
|
||||
#include "require_color_space.hpp"
|
||||
#include "convert_color_space.hpp"
|
||||
#include "image.hpp"
|
||||
|
||||
/**
|
||||
* \mainpage
|
||||
*
|
||||
* \section sec_intro Introduction
|
||||
*
|
||||
* This is the documentation for png++ the C++ wrapper for libpng.
|
||||
* This page documents png++ version 0.2.
|
||||
*
|
||||
* PNG++ aims to provide simple yet powerful C++ interface to libpng,
|
||||
* the PNG reference implementation library. PNG++ is free software
|
||||
* distributed under a modified variant of BSD <a
|
||||
* href="http://www.nongnu.org/pngpp/license.html">license</a>.
|
||||
*
|
||||
* \section sec_news News
|
||||
*
|
||||
* - Added support for tRNS chunk.
|
||||
* - Added non-std IO streams support.
|
||||
* - Fixed 16-bit endianness problems.
|
||||
* - Improved test script.
|
||||
*
|
||||
* \section sec_getting_started Getting started
|
||||
*
|
||||
* The following code demonstrates how to read and write PNG images
|
||||
* using png++:
|
||||
*
|
||||
* \code
|
||||
* png::image< png::rgb_pixel > image("input.png");
|
||||
* image.write("output.png");
|
||||
* \endcode
|
||||
*
|
||||
* The code reads an image from the file named \c input.png, then
|
||||
* writes the image to a file named \c output.png. The image class
|
||||
* template allows you to specify the desired pixel type for the image
|
||||
* data. The available pixel types include: RGB, Grayscale and
|
||||
* Indexed pixels. Some of the pixel types can have an alpha channel.
|
||||
*
|
||||
* The png++ naturally supports reading PNG images of any %color type
|
||||
* into RGB or Grayscale pixel buffers (with optional alpha channel).
|
||||
* This is particularly useful for an image viewer if it needs to
|
||||
* display the PNG image on, for example, RGB device regardless of the
|
||||
* image %color type.
|
||||
*
|
||||
* On the other hand one might want to read only images of particular
|
||||
* type. With png++ you can specify it this way:
|
||||
*
|
||||
* \code
|
||||
* png::image< png::rgb_pixel > image("rgb.png", png::require_color_space< png::rgb_pixel >());
|
||||
* \endcode
|
||||
*
|
||||
* \section sec_installing Installing
|
||||
*
|
||||
* PNG++ comes as a set of header files and does not require
|
||||
* compilation to be installed. For the same reason there are no
|
||||
* binary packages for png++.
|
||||
*
|
||||
* \subsection subs_prerequisites Prerequisites
|
||||
*
|
||||
* - png++ works with libpng-1.2.x.
|
||||
* - png++ compiles with g++-4.1 and g++-4.2. Other version should
|
||||
* work well too.
|
||||
* - png++ relies on GNU make for compiling tests and examples; in
|
||||
* particular it uses "remaking makefiles" feature
|
||||
* - Documentation is produced using <a
|
||||
* href="http://www.doxygen.org/">doxygen</a>. See the bottom of
|
||||
* this page for doxygen version used to compile these docs.
|
||||
*
|
||||
* \subsection subs_installing_pngpp Installing png++
|
||||
*
|
||||
* Follow these instructions in order to install png++:
|
||||
*
|
||||
* -# Unpack source package:
|
||||
* \verbatim $ tar -zxf png++-0.2.x.tar.gz -C ~/src \endverbatim
|
||||
* -# Go to your brand new png++ sources directory:
|
||||
* \verbatim $ cd ~/src/png++-0.2.x \endverbatim
|
||||
* -# Issue \c make to test how it's doing:
|
||||
* \verbatim $ make \endverbatim
|
||||
* This will compile examples in the \c example directory. If everything
|
||||
* goes well, try \verbatim $ make test \endverbatim (or \c make \c
|
||||
* check which is the same as above) to run the test suite. If tests
|
||||
* do not produce error messages then probably all is OK.
|
||||
* -# Now you can create documentation (optional). Use
|
||||
* \verbatim $ make docs \endverbatim
|
||||
* to run \c doxygen in the sources directory.
|
||||
* -# Now it is time to become \c root and install png++ into your
|
||||
* system. It's OK to issue \c make \c install under ordinary user
|
||||
* permissions if you want to install png++ into your home
|
||||
* directory. Run the following command:
|
||||
* \verbatim $ make install PREFIX=$HOME \endverbatim
|
||||
* to copy png++ header files to \c ~/include/png++ and documentation
|
||||
* files to <tt>~/share/doc/png++-0.2.x</tt>. Without a \c PREFIX png++
|
||||
* installs to \c /usr/local.
|
||||
*
|
||||
* \section sec_working_with_images Working with images
|
||||
*
|
||||
* In png++ you can create new images like this:
|
||||
*
|
||||
* \code
|
||||
* #include <png++/png.hpp>
|
||||
* //...
|
||||
* png::image< png::rgb_pixel > image(128, 128);
|
||||
* for (size_t y = 0; y < image.get_height(); ++y)
|
||||
* {
|
||||
* for (size_t x = 0; x < image.get_width(); ++x)
|
||||
* {
|
||||
* image[y][x] = png::rgb_pixel(x, y, x + y);
|
||||
* // non-checking equivalent of image.set_pixel(x, y, ...);
|
||||
* }
|
||||
* }
|
||||
* image.write("rgb.png");
|
||||
* \endcode
|
||||
*
|
||||
* Optionally, you may specify
|
||||
* \code
|
||||
* image.set_interlace_type(png::interlace_adam7)
|
||||
* \endcode
|
||||
* to produce an interlaced image.
|
||||
*
|
||||
* If you are writing an indexed colors image, you should provide a
|
||||
* palette (colormap). One of the ways to do this is the following:
|
||||
*
|
||||
* \code
|
||||
* #include <png++/png.hpp>
|
||||
* //...
|
||||
* png::image< png::index_pixel > image;
|
||||
* png::palette pal(256);
|
||||
* for (size_t i = 0; i < pal.size(); ++i)
|
||||
* {
|
||||
* pal[i] = png::color(i, 255 - i, i);
|
||||
* }
|
||||
* image.set_palette(pal);
|
||||
* ...
|
||||
* image.write("palette.png");
|
||||
* \endcode
|
||||
*
|
||||
* It is not absolutely necessary to have the whole image data in
|
||||
* memory in order to write a PNG file. You can use generator class
|
||||
* template to write the image row-by-row. An example of this is
|
||||
* provided in \c example/pixel_generator.cpp bundled with the sources
|
||||
* package.
|
||||
*
|
||||
* The same holds for reading images too. You can use consumer class
|
||||
* template in order to read the image data row-by-row. This might
|
||||
* help in applications which have to deal with large PNG images but
|
||||
* do not want to read the entire image into memory.
|
||||
*
|
||||
* You can read or write images from/to generic IO stream, not only
|
||||
* file on disk. Check out \c image::read(std::istream&),
|
||||
* \c image::write(std::ostream&) overloads in the reference manual.
|
||||
*
|
||||
* \section sec_compiling_user Compiling your programs
|
||||
*
|
||||
* Use the following command to compile your program:
|
||||
*
|
||||
* \verbatim $ g++ -c example.cpp `libpng-config --cflags` \endverbatim
|
||||
*
|
||||
* and the following to link it:
|
||||
*
|
||||
* \verbatim $ g++ -o example example.o `libpng-config --ldflags` \endverbatim
|
||||
*
|
||||
* When compiling you should add \c -I \c $PREFIX/include if you have
|
||||
* installed png++ to non-standard location, like your home directory.
|
||||
*
|
||||
* In your program, the line
|
||||
*
|
||||
* \code
|
||||
* #include <png++/png.hpp>
|
||||
* \endcode
|
||||
*
|
||||
* brings in all the header files in png++ which should be suitable
|
||||
* for the most of the applications. You may include only the headers
|
||||
* you really use, for example:
|
||||
*
|
||||
* \code
|
||||
* #include <png++/image.hpp>
|
||||
* #include <png++/rgb_pixel.hpp>
|
||||
* \endcode
|
||||
*
|
||||
* If do not want to install png++ headers you still can compile your
|
||||
* programs. Just create a subdirectory named \c png++ somewhere in
|
||||
* your project tree and copy all of the \c .hpp files in png++
|
||||
* distribution there. Then use appropriate compiler options to add
|
||||
* this directory into the header search path.
|
||||
*
|
||||
* \section sec_further Further reading
|
||||
*
|
||||
* - To get information about specific features, use reference (can be
|
||||
* reached from the top of this page).
|
||||
* - If you are looking for more example code, please go to the \c
|
||||
* example/ directory of the source distribution. You may also find
|
||||
* sources in the \c test/ directory insightful (well, somewhat).
|
||||
* - Have a question? Check out \ref sec_help section below.
|
||||
* - Of course, your ultimate source for learning is the source
|
||||
* code. <tt>:-)</tt>
|
||||
*
|
||||
* \section sec_download Download
|
||||
*
|
||||
* The project is hosted at Savannah:
|
||||
* http://savannah.nongnu.org/projects/pngpp/
|
||||
*
|
||||
* Released source packages can be found here:
|
||||
* http://download.savannah.nongnu.org/releases/pngpp/
|
||||
*
|
||||
* Also, you can check out sources directly from SVN repository:
|
||||
* svn://svn.sv.nongnu.org/pngpp/trunk/ or
|
||||
* http://svn.sv.nongnu.org/pngpp/trunk/ (for people w/o outgoing svn).
|
||||
*
|
||||
* Online version of this documentation can be found here:
|
||||
* http://www.nongnu.org/pngpp/doc/0.2.3/index.html
|
||||
*
|
||||
* \section sec_bugs Bugs
|
||||
*
|
||||
* The following is a list of known bugs and limitations:
|
||||
*
|
||||
* - Lacks support for output transformations
|
||||
* - Lacks support for optional/unknown chunks in PNG data stream
|
||||
* - Documentation sucks <tt>;-)</tt>
|
||||
*
|
||||
* To report bugs, please use Savannah bug tracker:
|
||||
* http://savannah.nongnu.org/bugs/?group=pngpp&func=additem
|
||||
*
|
||||
* Do not forget to check if the bug was already filed. <tt>:-)</tt>
|
||||
*
|
||||
* \section sec_help Getting help
|
||||
*
|
||||
* There is a mailing list for developers:
|
||||
* http://lists.nongnu.org/mailman/listinfo/pngpp-devel
|
||||
*
|
||||
* You can also contact me by dropping a mail to <alex.shulgin@gmail.com>.
|
||||
*
|
||||
* Happy hacking!
|
||||
*
|
||||
* Alex Shulgin
|
||||
*/
|
||||
|
||||
#endif // PNGPP_PNG_HPP_INCLUDED
|
@ -1,179 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_READER_HPP_INCLUDED
|
||||
#define PNGPP_READER_HPP_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
#include "io_base.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief The PNG reader class template. This is the low-level
|
||||
* reading interface--use image class or consumer class to
|
||||
* actually read images.
|
||||
*
|
||||
* The \c istream template parameter specifies the type of input
|
||||
* stream to work with. The \c istream class should implement the
|
||||
* minimum of the following interface:
|
||||
*
|
||||
* \code
|
||||
* class my_istream
|
||||
* {
|
||||
* public:
|
||||
* void read(char*, size_t);
|
||||
* bool good();
|
||||
* };
|
||||
* \endcode
|
||||
*
|
||||
* With the semantics similar to the \c std::istream. Naturally,
|
||||
* \c std::istream fits this requirement and can be used with the
|
||||
* reader class as is.
|
||||
*
|
||||
* \see image, consumer, writer, io_base
|
||||
*/
|
||||
template< class istream >
|
||||
class reader
|
||||
: public io_base
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief Constructs a reader prepared to read PNG image from
|
||||
* a \a stream.
|
||||
*/
|
||||
explicit reader(istream& stream)
|
||||
: io_base(png_create_read_struct(PNG_LIBPNG_VER_STRING,
|
||||
static_cast< io_base* >(this),
|
||||
raise_error,
|
||||
0))
|
||||
{
|
||||
png_set_read_fn(m_png, & stream, read_data);
|
||||
}
|
||||
|
||||
~reader()
|
||||
{
|
||||
png_destroy_read_struct(& m_png,
|
||||
m_info.get_png_info_ptr(),
|
||||
m_end_info.get_png_info_ptr());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads the whole PNG data stream into memory. Not
|
||||
* particularly useful.
|
||||
*/
|
||||
void read_png()
|
||||
{
|
||||
if (setjmp(png_jmpbuf(m_png)))
|
||||
{
|
||||
throw error(m_error);
|
||||
}
|
||||
png_read_png(m_png,
|
||||
m_info.get_png_info(),
|
||||
/* transforms = */ 0,
|
||||
/* params = */ 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads info about PNG image.
|
||||
*/
|
||||
void read_info()
|
||||
{
|
||||
if (setjmp(png_jmpbuf(m_png)))
|
||||
{
|
||||
throw error(m_error);
|
||||
}
|
||||
m_info.read();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads a row of image data at a time.
|
||||
*/
|
||||
void read_row(byte* bytes)
|
||||
{
|
||||
if (setjmp(png_jmpbuf(m_png)))
|
||||
{
|
||||
throw error(m_error);
|
||||
}
|
||||
png_read_row(m_png, bytes, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads ending info about PNG image.
|
||||
*/
|
||||
void read_end_info()
|
||||
{
|
||||
if (setjmp(png_jmpbuf(m_png)))
|
||||
{
|
||||
throw error(m_error);
|
||||
}
|
||||
m_end_info.read();
|
||||
}
|
||||
|
||||
void update_info()
|
||||
{
|
||||
m_info.update();
|
||||
}
|
||||
|
||||
private:
|
||||
static void read_data(png_struct* png, byte* data, size_t length)
|
||||
{
|
||||
io_base* io = static_cast< io_base* >(png_get_error_ptr(png));
|
||||
reader* rd = static_cast< reader* >(io);
|
||||
rd->reset_error();
|
||||
istream* stream = reinterpret_cast< istream* >(png_get_io_ptr(png));
|
||||
try
|
||||
{
|
||||
stream->read(reinterpret_cast< char* >(data), length);
|
||||
if (!stream->good())
|
||||
{
|
||||
rd->set_error("istream::read() failed");
|
||||
}
|
||||
}
|
||||
catch (std::exception const& error)
|
||||
{
|
||||
rd->set_error(error.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert(!"read_data: caught something wrong");
|
||||
rd->set_error("read_data: caught something wrong");
|
||||
}
|
||||
if (rd->is_error())
|
||||
{
|
||||
rd->raise_error();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_READER_HPP_INCLUDED
|
@ -1,171 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_REQUIRE_COLOR_SPACE_HPP_INCLUDED
|
||||
#define PNGPP_REQUIRE_COLOR_SPACE_HPP_INCLUDED
|
||||
|
||||
#include "error.hpp"
|
||||
#include "rgb_pixel.hpp"
|
||||
#include "rgba_pixel.hpp"
|
||||
#include "gray_pixel.hpp"
|
||||
#include "ga_pixel.hpp"
|
||||
#include "index_pixel.hpp"
|
||||
#include "io_base.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template< typename pixel >
|
||||
struct wrong_color_space
|
||||
{
|
||||
inline static char const* error_msg();
|
||||
};
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< rgb_pixel >::error_msg()
|
||||
{
|
||||
return "8-bit RGB color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< rgb_pixel_16 >::error_msg()
|
||||
{
|
||||
return "16-bit RGB color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< rgba_pixel >::error_msg()
|
||||
{
|
||||
return "8-bit RGBA color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< rgba_pixel_16 >::error_msg()
|
||||
{
|
||||
return "16-bit RGBA color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< gray_pixel >::error_msg()
|
||||
{
|
||||
return "8-bit Grayscale color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< gray_pixel_1 >::error_msg()
|
||||
{
|
||||
return "1-bit Grayscale color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< gray_pixel_2 >::error_msg()
|
||||
{
|
||||
return "2-bit Grayscale color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< gray_pixel_4 >::error_msg()
|
||||
{
|
||||
return "4-bit Grayscale color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< gray_pixel_16 >::error_msg()
|
||||
{
|
||||
return "16-bit Grayscale color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< ga_pixel >::error_msg()
|
||||
{
|
||||
return "8-bit Gray+Alpha color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< ga_pixel_16 >::error_msg()
|
||||
{
|
||||
return "16-bit Gray+Alpha color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< index_pixel >::error_msg()
|
||||
{
|
||||
return "8-bit Colormap color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< index_pixel_1 >::error_msg()
|
||||
{
|
||||
return "1-bit Colormap color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< index_pixel_2 >::error_msg()
|
||||
{
|
||||
return "2-bit Colormap color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< index_pixel_4 >::error_msg()
|
||||
{
|
||||
return "4-bit Colormap color space required";
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/**
|
||||
* \brief IO transformation class template. Enforces image color space.
|
||||
*
|
||||
* This IO transformation class template used to enforce source image
|
||||
* color space.
|
||||
*
|
||||
* \see image, image::read
|
||||
*/
|
||||
template< typename pixel >
|
||||
struct require_color_space
|
||||
{
|
||||
typedef pixel_traits< pixel > traits;
|
||||
|
||||
void operator()(io_base& io) const
|
||||
{
|
||||
if (io.get_color_type() != traits::get_color_type()
|
||||
|| io.get_bit_depth() != traits::get_bit_depth())
|
||||
{
|
||||
throw error(detail::wrong_color_space< pixel >::error_msg());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_REQUIRE_COLOR_SPACE_HPP_INCLUDED
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_RGB_PIXEL_HPP_INCLUDED
|
||||
#define PNGPP_RGB_PIXEL_HPP_INCLUDED
|
||||
|
||||
#include "types.hpp"
|
||||
#include "pixel_traits.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief RGB pixel type.
|
||||
*/
|
||||
template< typename T >
|
||||
struct basic_rgb_pixel
|
||||
{
|
||||
/**
|
||||
* \brief Default constructor. Initializes all components
|
||||
* with zeros.
|
||||
*/
|
||||
basic_rgb_pixel()
|
||||
: red(0), green(0), blue(0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Constructs rgb_pixel object from \a red, \a green
|
||||
* and \a blue components passed as parameters.
|
||||
*/
|
||||
basic_rgb_pixel(T red, T green, T blue)
|
||||
: red(red), green(green), blue(blue)
|
||||
{
|
||||
}
|
||||
|
||||
T red;
|
||||
T green;
|
||||
T blue;
|
||||
};
|
||||
|
||||
/**
|
||||
* The 8-bit RGB pixel type.
|
||||
*/
|
||||
typedef basic_rgb_pixel< byte > rgb_pixel;
|
||||
|
||||
/**
|
||||
* The 16-bit RGB pixel type.
|
||||
*/
|
||||
typedef basic_rgb_pixel< uint_16 > rgb_pixel_16;
|
||||
|
||||
/**
|
||||
* \brief Pixel traits specialization for basic_rgb_pixel.
|
||||
*/
|
||||
template< typename T >
|
||||
struct pixel_traits< basic_rgb_pixel< T > >
|
||||
: basic_pixel_traits< basic_rgb_pixel< T >, T, color_type_rgb >
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_RGB_PIXEL_HPP_INCLUDED
|
@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_RGBA_PIXEL_HPP_INCLUDED
|
||||
#define PNGPP_RGBA_PIXEL_HPP_INCLUDED
|
||||
|
||||
#include "types.hpp"
|
||||
#include "pixel_traits.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief RGBA pixel type.
|
||||
*/
|
||||
template< typename T >
|
||||
struct basic_rgba_pixel
|
||||
{
|
||||
typedef pixel_traits< basic_rgba_pixel< T > > traits;
|
||||
|
||||
/**
|
||||
* \brief Default constructor. Initializes all components
|
||||
* with zeros.
|
||||
*/
|
||||
basic_rgba_pixel()
|
||||
: red(0), green(0), blue(0), alpha(0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Constructs rgba_pixel object from \a red, \a green,
|
||||
* \a blue and \a alpha components passed as parameters.
|
||||
* Alpha defaults to full opacity.
|
||||
*/
|
||||
basic_rgba_pixel(T red, T green, T blue,
|
||||
T alpha = traits::get_alpha_filler())
|
||||
: red(red), green(green), blue(blue), alpha(alpha)
|
||||
{
|
||||
}
|
||||
|
||||
T red;
|
||||
T green;
|
||||
T blue;
|
||||
T alpha;
|
||||
};
|
||||
|
||||
/**
|
||||
* The 8-bit RGBA pixel type.
|
||||
*/
|
||||
typedef basic_rgba_pixel< byte > rgba_pixel;
|
||||
|
||||
/**
|
||||
* The 16-bit RGBA pixel type.
|
||||
*/
|
||||
typedef basic_rgba_pixel< uint_16 > rgba_pixel_16;
|
||||
|
||||
/**
|
||||
* \brief Pixel traits specialization for basic_rgba_pixel.
|
||||
*/
|
||||
template< typename T >
|
||||
struct pixel_traits< basic_rgba_pixel< T > >
|
||||
: basic_pixel_traits< basic_rgba_pixel< T >, T, color_type_rgba >,
|
||||
basic_alpha_pixel_traits< T >
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_RGBA_PIXEL_HPP_INCLUDED
|
@ -1,128 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_STREAMING_BASE_HPP_INCLUDED
|
||||
#define PNGPP_STREAMING_BASE_HPP_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
#include "image_info.hpp"
|
||||
#include "pixel_traits.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief The default image_info holder class. Stores image_info
|
||||
* member object.
|
||||
*/
|
||||
class def_image_info_holder
|
||||
{
|
||||
public:
|
||||
def_image_info_holder(image_info const& info)
|
||||
: m_info(info)
|
||||
{
|
||||
}
|
||||
|
||||
image_info& get_info()
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
|
||||
private:
|
||||
image_info m_info;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief An image_info holder class. Stores a reference to the
|
||||
* image_info object. The image_info object itself should be
|
||||
* stored elsewhere.
|
||||
*/
|
||||
class image_info_ref_holder
|
||||
{
|
||||
public:
|
||||
image_info_ref_holder(image_info& info)
|
||||
: m_info(info)
|
||||
{
|
||||
}
|
||||
|
||||
image_info& get_info()
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
|
||||
private:
|
||||
image_info& m_info;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief A base class template for consumer and generator
|
||||
* classes. Provides default \c reset() method implementation as
|
||||
* well as \c info_holder policy.
|
||||
*/
|
||||
template< typename pixel, class info_holder >
|
||||
class streaming_base
|
||||
{
|
||||
public:
|
||||
typedef pixel_traits< pixel > traits;
|
||||
|
||||
explicit streaming_base(image_info& info)
|
||||
: m_info_holder(info)
|
||||
{
|
||||
}
|
||||
|
||||
streaming_base(size_t width, size_t height)
|
||||
: m_info_holder(make_image_info< pixel >())
|
||||
{
|
||||
get_info().set_width(width);
|
||||
get_info().set_height(height);
|
||||
}
|
||||
|
||||
image_info const& get_info() const
|
||||
{
|
||||
return m_info_holder.get_info();
|
||||
}
|
||||
|
||||
protected:
|
||||
void reset(size_t /*pass*/)
|
||||
{
|
||||
// nothing to do in the most general case
|
||||
}
|
||||
|
||||
image_info& get_info()
|
||||
{
|
||||
return m_info_holder.get_info();
|
||||
}
|
||||
|
||||
info_holder m_info_holder;
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_STREAMING_BASE_HPP_INCLUDED
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_TRNS_HPP_INCLUDED
|
||||
#define PNGPP_TRNS_HPP_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
#include "color.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief The palette transparency map type. Currently
|
||||
* implemented as \c std::vector of png::byte.
|
||||
*/
|
||||
typedef std::vector< byte > tRNS;
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_TRNS_HPP_INCLUDED
|
@ -1,120 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_TYPES_HPP_INCLUDED
|
||||
#define PNGPP_TYPES_HPP_INCLUDED
|
||||
|
||||
#include <png.h>
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
typedef png_byte byte;
|
||||
typedef png_uint_16 uint_16;
|
||||
typedef png_uint_32 uint_32;
|
||||
typedef png_fixed_point fixed_point;
|
||||
typedef png_color_8 color_info;
|
||||
typedef png_color_16 color_info_16;
|
||||
|
||||
enum color_type
|
||||
{
|
||||
color_type_none = -1,
|
||||
color_type_gray = PNG_COLOR_TYPE_GRAY,
|
||||
color_type_palette = PNG_COLOR_TYPE_PALETTE,
|
||||
color_type_rgb = PNG_COLOR_TYPE_RGB,
|
||||
color_type_rgb_alpha = PNG_COLOR_TYPE_RGB_ALPHA,
|
||||
color_type_gray_alpha = PNG_COLOR_TYPE_GRAY_ALPHA,
|
||||
color_type_rgba = PNG_COLOR_TYPE_RGBA,
|
||||
color_type_ga = PNG_COLOR_TYPE_GA
|
||||
};
|
||||
|
||||
enum color_mask
|
||||
{
|
||||
color_mask_palette = PNG_COLOR_MASK_PALETTE,
|
||||
color_mask_color = PNG_COLOR_MASK_COLOR,
|
||||
color_mask_rgb = color_mask_color,
|
||||
color_mask_alpha = PNG_COLOR_MASK_ALPHA
|
||||
};
|
||||
|
||||
enum filler_type
|
||||
{
|
||||
filler_before = PNG_FILLER_BEFORE,
|
||||
filler_after = PNG_FILLER_AFTER
|
||||
};
|
||||
|
||||
enum rgb_to_gray_error_action
|
||||
{
|
||||
rgb_to_gray_silent = 1,
|
||||
rgb_to_gray_warning = 2,
|
||||
rgb_to_gray_error = 3
|
||||
};
|
||||
|
||||
enum interlace_type
|
||||
{
|
||||
interlace_none = PNG_INTERLACE_NONE,
|
||||
interlace_adam7 = PNG_INTERLACE_ADAM7
|
||||
};
|
||||
|
||||
enum compression_type
|
||||
{
|
||||
compression_type_base = PNG_COMPRESSION_TYPE_BASE,
|
||||
compression_type_default = PNG_COMPRESSION_TYPE_DEFAULT
|
||||
};
|
||||
|
||||
enum filter_type
|
||||
{
|
||||
filter_type_base = PNG_FILTER_TYPE_BASE,
|
||||
intrapixel_differencing = PNG_INTRAPIXEL_DIFFERENCING,
|
||||
filter_type_default = PNG_FILTER_TYPE_DEFAULT
|
||||
};
|
||||
|
||||
enum chunk
|
||||
{
|
||||
chunk_gAMA = PNG_INFO_gAMA,
|
||||
chunk_sBIT = PNG_INFO_sBIT,
|
||||
chunk_cHRM = PNG_INFO_cHRM,
|
||||
chunk_PLTE = PNG_INFO_PLTE,
|
||||
chunk_tRNS = PNG_INFO_tRNS,
|
||||
chunk_bKGD = PNG_INFO_bKGD,
|
||||
chunk_hIST = PNG_INFO_hIST,
|
||||
chunk_pHYs = PNG_INFO_pHYs,
|
||||
chunk_oFFs = PNG_INFO_oFFs,
|
||||
chunk_tIME = PNG_INFO_tIME,
|
||||
chunk_pCAL = PNG_INFO_pCAL,
|
||||
chunk_sRGB = PNG_INFO_sRGB,
|
||||
chunk_iCCP = PNG_INFO_iCCP,
|
||||
chunk_sPLT = PNG_INFO_sPLT,
|
||||
chunk_sCAL = PNG_INFO_sCAL,
|
||||
chunk_IDAT = PNG_INFO_IDAT
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_TYPES_HPP_INCLUDED
|
@ -1,199 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PNGPP_WRITER_HPP_INCLUDED
|
||||
#define PNGPP_WRITER_HPP_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
#include "io_base.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief PNG writer class template. This is the low-level
|
||||
* writing interface--use image class or generator class to
|
||||
* actually write images.
|
||||
*
|
||||
* The \c ostream template parameter specifies the type of output
|
||||
* stream to work with. The \c ostream class should implement the
|
||||
* minimum of the following interface:
|
||||
*
|
||||
* \code
|
||||
* class my_ostream
|
||||
* {
|
||||
* public:
|
||||
* void write(char const*, size_t);
|
||||
* void flush();
|
||||
* bool good();
|
||||
* };
|
||||
* \endcode
|
||||
*
|
||||
* With the semantics similar to the \c std::ostream. Naturally,
|
||||
* \c std::ostream fits this requirement and can be used with the
|
||||
* writer class as is.
|
||||
*
|
||||
* \see image, reader, generator, io_base
|
||||
*/
|
||||
template< class ostream >
|
||||
class writer
|
||||
: public io_base
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief Constructs a writer prepared to write PNG image into
|
||||
* a \a stream.
|
||||
*/
|
||||
explicit writer(ostream& stream)
|
||||
: io_base(png_create_write_struct(PNG_LIBPNG_VER_STRING,
|
||||
static_cast< io_base* >(this),
|
||||
raise_error,
|
||||
0))
|
||||
{
|
||||
png_set_write_fn(m_png, & stream, write_data, flush_data);
|
||||
}
|
||||
|
||||
~writer()
|
||||
{
|
||||
m_end_info.destroy();
|
||||
png_destroy_write_struct(& m_png, m_info.get_png_info_ptr());
|
||||
}
|
||||
|
||||
void write_png() const
|
||||
{
|
||||
if (setjmp(png_jmpbuf(m_png)))
|
||||
{
|
||||
throw error(m_error);
|
||||
}
|
||||
png_write_png(m_png,
|
||||
m_info.get_png_info(),
|
||||
/* transforms = */ 0,
|
||||
/* params = */ 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Write info about PNG image.
|
||||
*/
|
||||
void write_info() const
|
||||
{
|
||||
if (setjmp(png_jmpbuf(m_png)))
|
||||
{
|
||||
throw error(m_error);
|
||||
}
|
||||
m_info.write();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Writes a row of image data at a time.
|
||||
*/
|
||||
void write_row(byte* bytes)
|
||||
{
|
||||
if (setjmp(png_jmpbuf(m_png)))
|
||||
{
|
||||
throw error(m_error);
|
||||
}
|
||||
png_write_row(m_png, bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads ending info about PNG image.
|
||||
*/
|
||||
void write_end_info() const
|
||||
{
|
||||
if (setjmp(png_jmpbuf(m_png)))
|
||||
{
|
||||
throw error(m_error);
|
||||
}
|
||||
m_end_info.write();
|
||||
}
|
||||
|
||||
private:
|
||||
static void write_data(png_struct* png, byte* data, size_t length)
|
||||
{
|
||||
io_base* io = static_cast< io_base* >(png_get_error_ptr(png));
|
||||
writer* wr = static_cast< writer* >(io);
|
||||
wr->reset_error();
|
||||
ostream* stream = reinterpret_cast< ostream* >(png_get_io_ptr(png));
|
||||
try
|
||||
{
|
||||
stream->write(reinterpret_cast< char* >(data), length);
|
||||
if (!stream->good())
|
||||
{
|
||||
wr->set_error("ostream::write() failed");
|
||||
}
|
||||
}
|
||||
catch (std::exception const& error)
|
||||
{
|
||||
wr->set_error(error.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert(!"caught something wrong");
|
||||
wr->set_error("write_data: caught something wrong");
|
||||
}
|
||||
if (wr->is_error())
|
||||
{
|
||||
wr->raise_error();
|
||||
}
|
||||
}
|
||||
|
||||
static void flush_data(png_struct* png)
|
||||
{
|
||||
io_base* io = static_cast< io_base* >(png_get_error_ptr(png));
|
||||
writer* wr = static_cast< writer* >(io);
|
||||
wr->reset_error();
|
||||
ostream* stream = reinterpret_cast< ostream* >(png_get_io_ptr(png));
|
||||
try
|
||||
{
|
||||
stream->flush();
|
||||
if (!stream->good())
|
||||
{
|
||||
wr->set_error("ostream::flush() failed");
|
||||
}
|
||||
}
|
||||
catch (std::exception const& error)
|
||||
{
|
||||
wr->set_error(error.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert(!"caught something wrong");
|
||||
wr->set_error("flush_data: caught something wrong");
|
||||
}
|
||||
if (wr->is_error())
|
||||
{
|
||||
wr->raise_error();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_WRITER_HPP_INCLUDED
|
Loading…
Reference in New Issue
Block a user