2006-03-31 12:32:02 +02:00
|
|
|
/*****************************************************************************
|
2012-02-02 02:53:35 +01:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
2005-06-14 17:06:59 +02:00
|
|
|
*
|
2011-10-23 15:04:25 +02:00
|
|
|
* Copyright (C) 2011 Artem Pavlenko
|
2005-06-14 17:06:59 +02:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
2005-06-14 17:06:59 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2006-03-31 12:32:02 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-06-14 17:06:59 +02:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
*****************************************************************************/
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2006-10-04 13:22:18 +02:00
|
|
|
// mapnik
|
2012-04-08 02:20:56 +02:00
|
|
|
#include <mapnik/debug.hpp>
|
2006-10-04 13:22:18 +02:00
|
|
|
#include <mapnik/image_reader.hpp>
|
2013-06-03 04:28:24 +02:00
|
|
|
|
2012-09-24 14:35:22 +02:00
|
|
|
// boost
|
|
|
|
#include <boost/shared_ptr.hpp>
|
2013-06-03 04:28:24 +02:00
|
|
|
|
2013-05-13 11:26:28 +02:00
|
|
|
// iostreams
|
|
|
|
#include <boost/iostreams/device/file.hpp>
|
|
|
|
#include <boost/iostreams/device/array.hpp>
|
|
|
|
#include <boost/iostreams/stream.hpp>
|
2009-12-16 21:02:06 +01:00
|
|
|
|
2012-02-02 02:53:35 +01:00
|
|
|
extern "C"
|
2006-08-31 23:32:07 +02:00
|
|
|
{
|
2012-02-02 02:53:35 +01:00
|
|
|
#include <tiffio.h>
|
2006-08-31 23:32:07 +02:00
|
|
|
}
|
|
|
|
|
2013-08-30 10:46:09 +02:00
|
|
|
namespace mapnik { namespace impl {
|
2006-04-05 10:27:45 +02:00
|
|
|
|
2013-05-13 11:26:28 +02:00
|
|
|
static toff_t tiff_seek_proc(thandle_t fd, toff_t off, int whence)
|
|
|
|
{
|
|
|
|
std::istream* in = reinterpret_cast<std::istream*>(fd);
|
|
|
|
|
|
|
|
switch(whence)
|
|
|
|
{
|
|
|
|
case SEEK_SET:
|
|
|
|
in->seekg(off, std::ios_base::beg);
|
|
|
|
break;
|
|
|
|
case SEEK_CUR:
|
|
|
|
in->seekg(off, std::ios_base::cur);
|
|
|
|
break;
|
|
|
|
case SEEK_END:
|
|
|
|
in->seekg(off, std::ios_base::end);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return static_cast<toff_t>(in->tellg());
|
|
|
|
}
|
|
|
|
|
2013-08-30 10:46:09 +02:00
|
|
|
static int tiff_close_proc(thandle_t)
|
2013-05-13 11:26:28 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static toff_t tiff_size_proc(thandle_t fd)
|
|
|
|
{
|
|
|
|
std::istream* in = reinterpret_cast<std::istream*>(fd);
|
|
|
|
std::ios::pos_type pos = in->tellg();
|
|
|
|
in->seekg(0, std::ios::end);
|
|
|
|
std::ios::pos_type len = in->tellg();
|
|
|
|
in->seekg(pos);
|
|
|
|
return static_cast<toff_t>(len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static tsize_t tiff_read_proc(thandle_t fd, tdata_t buf, tsize_t size)
|
|
|
|
{
|
|
|
|
std::istream * in = reinterpret_cast<std::istream*>(fd);
|
|
|
|
std::streamsize request_size = size;
|
2013-05-13 20:00:21 +02:00
|
|
|
if (static_cast<tsize_t>(request_size) != size)
|
|
|
|
return static_cast<tsize_t>(-1);
|
2013-05-13 11:26:28 +02:00
|
|
|
in->read(reinterpret_cast<char*>(buf), request_size);
|
2013-05-13 20:00:21 +02:00
|
|
|
return static_cast<tsize_t>(in->gcount());
|
2013-05-13 11:26:28 +02:00
|
|
|
}
|
|
|
|
|
2013-08-30 10:46:09 +02:00
|
|
|
static tsize_t tiff_write_proc(thandle_t , tdata_t , tsize_t)
|
2013-05-13 11:26:28 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-30 10:46:09 +02:00
|
|
|
static void tiff_unmap_proc(thandle_t, tdata_t, toff_t)
|
2013-05-13 11:26:28 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-08-30 10:46:09 +02:00
|
|
|
static int tiff_map_proc(thandle_t, tdata_t* , toff_t*)
|
2013-05-13 11:26:28 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2010-06-02 13:03:30 +02:00
|
|
|
class tiff_reader : public image_reader
|
|
|
|
{
|
2013-09-20 15:00:11 +02:00
|
|
|
typedef std::shared_ptr<TIFF> tiff_ptr;
|
2013-05-13 11:26:28 +02:00
|
|
|
typedef T source_type;
|
|
|
|
typedef boost::iostreams::stream<source_type> input_stream;
|
|
|
|
|
2012-09-24 14:35:22 +02:00
|
|
|
struct tiff_closer
|
|
|
|
{
|
|
|
|
void operator() (TIFF * tif)
|
|
|
|
{
|
|
|
|
if (tif != 0)
|
|
|
|
{
|
|
|
|
TIFFClose(tif);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
private:
|
2013-05-13 11:26:28 +02:00
|
|
|
source_type source_;
|
|
|
|
input_stream stream_;
|
2010-06-02 13:03:30 +02:00
|
|
|
int read_method_;
|
2013-05-13 11:26:28 +02:00
|
|
|
std::size_t width_;
|
|
|
|
std::size_t height_;
|
2010-06-02 13:03:30 +02:00
|
|
|
int rows_per_strip_;
|
|
|
|
int tile_width_;
|
|
|
|
int tile_height_;
|
2012-09-24 14:35:22 +02:00
|
|
|
tiff_ptr tif_;
|
2012-09-28 17:37:21 +02:00
|
|
|
bool premultiplied_alpha_;
|
2010-06-02 13:03:30 +02:00
|
|
|
public:
|
|
|
|
enum TiffType {
|
|
|
|
generic=1,
|
|
|
|
stripped,
|
|
|
|
tiled
|
2005-06-14 17:06:59 +02:00
|
|
|
};
|
2012-09-03 19:27:48 +02:00
|
|
|
explicit tiff_reader(std::string const& file_name);
|
2013-05-13 11:26:28 +02:00
|
|
|
tiff_reader(char const* data, std::size_t size);
|
2010-06-02 13:03:30 +02:00
|
|
|
virtual ~tiff_reader();
|
|
|
|
unsigned width() const;
|
|
|
|
unsigned height() const;
|
2012-09-28 17:37:21 +02:00
|
|
|
bool premultiplied_alpha() const;
|
2010-06-02 13:03:30 +02:00
|
|
|
void read(unsigned x,unsigned y,image_data_32& image);
|
|
|
|
private:
|
|
|
|
tiff_reader(const tiff_reader&);
|
|
|
|
tiff_reader& operator=(const tiff_reader&);
|
|
|
|
void init();
|
|
|
|
void read_generic(unsigned x,unsigned y,image_data_32& image);
|
|
|
|
void read_stripped(unsigned x,unsigned y,image_data_32& image);
|
|
|
|
void read_tiled(unsigned x,unsigned y,image_data_32& image);
|
2013-05-13 11:26:28 +02:00
|
|
|
TIFF* open(std::istream & input);
|
2013-08-30 10:46:09 +02:00
|
|
|
static void on_error(const char* , const char* fmt, va_list argptr);
|
2010-06-02 13:03:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2013-05-13 11:26:28 +02:00
|
|
|
|
2012-09-03 19:27:48 +02:00
|
|
|
image_reader* create_tiff_reader(std::string const& file)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2013-05-13 11:26:28 +02:00
|
|
|
return new tiff_reader<boost::iostreams::file_source>(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
image_reader* create_tiff_reader2(char const * data, std::size_t size)
|
|
|
|
{
|
|
|
|
return new tiff_reader<boost::iostreams::array_source>(data, size);
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
const bool registered = register_image_reader("tiff",create_tiff_reader);
|
2013-05-13 11:26:28 +02:00
|
|
|
const bool registered2 = register_image_reader("tiff", create_tiff_reader2);
|
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
|
|
|
|
2013-05-13 11:26:28 +02:00
|
|
|
template <typename T>
|
|
|
|
tiff_reader<T>::tiff_reader(std::string const& file_name)
|
|
|
|
: source_(file_name, std::ios_base::in | std::ios_base::binary),
|
|
|
|
stream_(source_),
|
2010-06-02 13:03:30 +02:00
|
|
|
read_method_(generic),
|
|
|
|
width_(0),
|
|
|
|
height_(0),
|
|
|
|
rows_per_strip_(0),
|
|
|
|
tile_width_(0),
|
2012-09-28 17:37:21 +02:00
|
|
|
tile_height_(0),
|
|
|
|
premultiplied_alpha_(false)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2013-05-13 11:26:28 +02:00
|
|
|
if (!stream_) throw image_reader_exception("TIFF reader: cannot open file "+ file_name);
|
2010-06-02 13:03:30 +02:00
|
|
|
init();
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2013-05-13 11:26:28 +02:00
|
|
|
template <typename T>
|
|
|
|
tiff_reader<T>::tiff_reader(char const* data, std::size_t size)
|
|
|
|
: source_(data, size),
|
|
|
|
stream_(source_),
|
|
|
|
read_method_(generic),
|
|
|
|
width_(0),
|
|
|
|
height_(0),
|
|
|
|
rows_per_strip_(0),
|
|
|
|
tile_width_(0),
|
|
|
|
tile_height_(0),
|
|
|
|
premultiplied_alpha_(false)
|
|
|
|
{
|
|
|
|
if (!stream_) throw image_reader_exception("TIFF reader: cannot open image stream ");
|
|
|
|
stream_.seekg(0, std::ios::beg);
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2013-08-30 10:46:09 +02:00
|
|
|
void tiff_reader<T>::on_error(const char* , const char* fmt, va_list argptr)
|
2013-03-26 02:29:29 +01:00
|
|
|
{
|
|
|
|
char msg[10240];
|
|
|
|
vsprintf(msg, fmt, argptr);
|
|
|
|
throw image_reader_exception(msg);
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2013-05-13 11:26:28 +02:00
|
|
|
template <typename T>
|
|
|
|
void tiff_reader<T>::init()
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2013-04-10 04:16:05 +02:00
|
|
|
TIFFSetWarningHandler(0);
|
|
|
|
// Note - we intentially set the error handling to null
|
|
|
|
// when opening the image for the first time to avoid
|
|
|
|
// leaking in TiffOpen: https://github.com/mapnik/mapnik/issues/1783
|
|
|
|
TIFFSetErrorHandler(0);
|
2013-05-13 11:26:28 +02:00
|
|
|
|
|
|
|
TIFF* tif = open(stream_);
|
|
|
|
|
|
|
|
if (!tif) throw image_reader_exception("Can't open tiff file");
|
|
|
|
|
2013-04-10 04:08:50 +02:00
|
|
|
TIFFSetErrorHandler(on_error);
|
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
char msg[1024];
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
if (TIFFRGBAImageOK(tif,msg))
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width_);
|
|
|
|
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height_);
|
|
|
|
if (TIFFIsTiled(tif))
|
2006-04-05 10:27:45 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tile_width_);
|
|
|
|
TIFFGetField(tif, TIFFTAG_TILELENGTH, &tile_height_);
|
|
|
|
read_method_=tiled;
|
2006-04-05 10:27:45 +02:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
else if (TIFFGetField(tif,TIFFTAG_ROWSPERSTRIP,&rows_per_strip_)!=0)
|
2006-04-05 10:27:45 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
read_method_=stripped;
|
2006-04-05 10:27:45 +02:00
|
|
|
}
|
2012-09-28 17:37:21 +02:00
|
|
|
//TIFFTAG_EXTRASAMPLES
|
|
|
|
uint16 extrasamples;
|
|
|
|
uint16* sampleinfo;
|
|
|
|
TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES,
|
|
|
|
&extrasamples, &sampleinfo);
|
|
|
|
if (extrasamples == 1 &&
|
|
|
|
sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA)
|
|
|
|
{
|
|
|
|
premultiplied_alpha_ = true;
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
else
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
throw image_reader_exception(msg);
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2013-05-13 11:26:28 +02:00
|
|
|
template <typename T>
|
|
|
|
tiff_reader<T>::~tiff_reader()
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2013-05-13 11:26:28 +02:00
|
|
|
template <typename T>
|
|
|
|
unsigned tiff_reader<T>::width() const
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
return width_;
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2013-05-13 11:26:28 +02:00
|
|
|
template <typename T>
|
|
|
|
unsigned tiff_reader<T>::height() const
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
return height_;
|
|
|
|
}
|
|
|
|
|
2013-05-13 11:26:28 +02:00
|
|
|
template <typename T>
|
|
|
|
bool tiff_reader<T>::premultiplied_alpha() const
|
2012-09-28 17:37:21 +02:00
|
|
|
{
|
|
|
|
return premultiplied_alpha_;
|
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
|
2013-05-13 11:26:28 +02:00
|
|
|
template <typename T>
|
|
|
|
void tiff_reader<T>::read(unsigned x,unsigned y,image_data_32& image)
|
2012-02-02 02:53:35 +01:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
if (read_method_==stripped)
|
|
|
|
{
|
|
|
|
read_stripped(x,y,image);
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
else if (read_method_==tiled)
|
|
|
|
{
|
|
|
|
read_tiled(x,y,image);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
read_generic(x,y,image);
|
|
|
|
}
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2013-05-13 11:26:28 +02:00
|
|
|
template <typename T>
|
2013-08-30 10:46:09 +02:00
|
|
|
void tiff_reader<T>::read_generic(unsigned, unsigned, image_data_32&)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2013-05-13 11:26:28 +02:00
|
|
|
TIFF* tif = open(stream_);
|
2010-06-02 13:03:30 +02:00
|
|
|
if (tif)
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
2012-04-09 21:41:56 +02:00
|
|
|
MAPNIK_LOG_DEBUG(tiff_reader) << "tiff_reader: TODO - tiff is not stripped or tiled";
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2013-05-13 11:26:28 +02:00
|
|
|
template <typename T>
|
|
|
|
void tiff_reader<T>::read_tiled(unsigned x0,unsigned y0,image_data_32& image)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2013-05-13 11:26:28 +02:00
|
|
|
TIFF* tif = open(stream_);
|
2010-06-02 13:03:30 +02:00
|
|
|
if (tif)
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
uint32* buf = (uint32*)_TIFFmalloc(tile_width_*tile_height_*sizeof(uint32));
|
|
|
|
int width=image.width();
|
|
|
|
int height=image.height();
|
2006-04-05 10:27:45 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
int start_y=(y0/tile_height_)*tile_height_;
|
|
|
|
int end_y=((y0+height)/tile_height_+1)*tile_height_;
|
2006-04-05 10:27:45 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
int start_x=(x0/tile_width_)*tile_width_;
|
|
|
|
int end_x=((x0+width)/tile_width_+1)*tile_width_;
|
|
|
|
int row,tx0,tx1,ty0,ty1;
|
2006-04-05 10:27:45 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
for (int y=start_y;y<end_y;y+=tile_height_)
|
|
|
|
{
|
2013-05-13 11:26:28 +02:00
|
|
|
ty0 = std::max(y0,(unsigned)y) - y;
|
|
|
|
ty1 = std::min(height+y0,(unsigned)(y+tile_height_)) - y;
|
2006-04-05 10:27:45 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
int n0=tile_height_-ty1;
|
|
|
|
int n1=tile_height_-ty0-1;
|
2006-04-05 10:27:45 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
for (int x=start_x;x<end_x;x+=tile_width_)
|
|
|
|
{
|
2006-04-05 10:27:45 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
if (!TIFFReadRGBATile(tif,x,y,buf)) break;
|
2006-04-05 10:27:45 +02:00
|
|
|
|
2013-05-13 11:26:28 +02:00
|
|
|
tx0=std::max(x0,(unsigned)x);
|
|
|
|
tx1=std::min(width+x0,(unsigned)(x+tile_width_));
|
2010-06-02 13:03:30 +02:00
|
|
|
row=y+ty0-y0;
|
|
|
|
for (int n=n1;n>=n0;--n)
|
|
|
|
{
|
|
|
|
image.setRow(row,tx0-x0,tx1-x0,(const unsigned*)&buf[n*tile_width_+tx0-x]);
|
|
|
|
++row;
|
2006-04-05 10:27:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
_TIFFfree(buf);
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2013-05-13 11:26:28 +02:00
|
|
|
template <typename T>
|
|
|
|
void tiff_reader<T>::read_stripped(unsigned x0,unsigned y0,image_data_32& image)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2013-05-13 11:26:28 +02:00
|
|
|
TIFF* tif = open(stream_);
|
2010-06-02 13:03:30 +02:00
|
|
|
if (tif)
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
uint32* buf = (uint32*)_TIFFmalloc(width_*rows_per_strip_*sizeof(uint32));
|
2006-04-05 10:27:45 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
int width=image.width();
|
|
|
|
int height=image.height();
|
2006-04-05 10:27:45 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
unsigned start_y=(y0/rows_per_strip_)*rows_per_strip_;
|
|
|
|
unsigned end_y=((y0+height)/rows_per_strip_+1)*rows_per_strip_;
|
|
|
|
bool laststrip=((unsigned)end_y > height_)?true:false;
|
|
|
|
int row,tx0,tx1,ty0,ty1;
|
2006-04-05 10:27:45 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
tx0=x0;
|
2013-05-13 11:26:28 +02:00
|
|
|
tx1=std::min(width+x0,(unsigned)width_);
|
2006-04-05 10:27:45 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
for (unsigned y=start_y; y < end_y; y+=rows_per_strip_)
|
|
|
|
{
|
2013-05-13 11:26:28 +02:00
|
|
|
ty0 = std::max(y0,y)-y;
|
|
|
|
ty1 = std::min(height+y0,y+rows_per_strip_)-y;
|
2006-04-05 10:27:45 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
if (!TIFFReadRGBAStrip(tif,y,buf)) break;
|
2006-04-05 10:27:45 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
row=y+ty0-y0;
|
2006-04-05 10:27:45 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
int n0=laststrip ? 0:(rows_per_strip_-ty1);
|
|
|
|
int n1=laststrip ? (ty1-ty0-1):(rows_per_strip_-ty0-1);
|
|
|
|
for (int n=n1;n>=n0;--n)
|
|
|
|
{
|
|
|
|
image.setRow(row,tx0-x0,tx1-x0,(const unsigned*)&buf[n*width_+tx0]);
|
|
|
|
++row;
|
2006-04-05 10:27:45 +02:00
|
|
|
}
|
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
_TIFFfree(buf);
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2013-05-13 11:26:28 +02:00
|
|
|
template <typename T>
|
|
|
|
TIFF* tiff_reader<T>::open(std::istream & input)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2012-09-24 14:35:22 +02:00
|
|
|
if (!tif_)
|
2012-02-02 02:53:35 +01:00
|
|
|
{
|
2013-05-13 11:26:28 +02:00
|
|
|
tif_ = tiff_ptr(TIFFClientOpen("tiff_input_stream", "rm",
|
|
|
|
reinterpret_cast<thandle_t>(&input),
|
|
|
|
impl::tiff_read_proc,
|
|
|
|
impl::tiff_write_proc,
|
|
|
|
impl::tiff_seek_proc,
|
|
|
|
impl::tiff_close_proc,
|
|
|
|
impl::tiff_size_proc,
|
|
|
|
impl::tiff_map_proc,
|
|
|
|
impl::tiff_unmap_proc), tiff_closer());
|
2006-12-20 01:22:45 +01:00
|
|
|
}
|
2012-09-24 14:35:22 +02:00
|
|
|
return tif_.get();
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
|
|
|
|
2012-09-24 14:35:22 +02:00
|
|
|
} // namespace mapnik
|