代码拉取完成,页面将自动刷新
#include <xtiffio.h>
#include "GeoTiffWriter.hxx"
#include "GeoTiffImage.hxx"
GeoTiffWriter::GeoTiffWriter()
{
_fileName[0] = '\0';
_image = 0;
}
GeoTiffWriter::~GeoTiffWriter()
{
}
void GeoTiffWriter::write()
{
if( _image == 0 )
{
fprintf(stderr, "Need a GeoTiffImage to write.\n");
return;
}
TIFF *tif = 0;
tif = XTIFFOpen(_fileName, "w");
if (!tif) {
fprintf(stderr, "Can't create test TIFF file %s.\n", _fileName);
return;
}
setUpTIFFDirectory(tif);
double scale[3] = { 0.0, 0.0, 0.0 };
double pos[6] = { 0.0, 0.0,0.0,0.0, 0.0,0.0};
_image->getGeoScale(scale[0], scale[1], scale[2]);
_image->getGeoModelCoord(pos[3], pos[4], pos[5]);
TIFFSetField(tif, TIFFTAG_GEOPIXELSCALE, 3, scale);
TIFFSetField(tif, TIFFTAG_GEOTIEPOINTS, 6, pos);
// TIFFSetField(tif, TIFFTAG_GEOKEYDIRECTORY, 56, tifImage->getGeoKeyDirectory());
// TIFFSetField(tif, TIFFTAG_GEODOUBLEPARAMS, 4, tifImage->getGeoDoubleParams());
// TIFFSetField(tif, TIFFTAG_GEOASCIIPARAMS, tifImage->getGeoAsciiParams());
int lineSize = _image->getWidth() * _image->getChannels() * _image->getDepth() / 8;
for (int i = 0; i < _image->getHeight(); i++)
{
unsigned char* buf = _image->getImageData() + i * lineSize;
if (TIFFWriteScanline(tif, buf, i, 0) == -1)
{
fprintf(stderr, "Can't write image data.\n");
XTIFFClose(tif);
}
}
XTIFFClose(tif);
}
void GeoTiffWriter::setUpTIFFDirectory(TIFF* tif)
{
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, _image->getWidth());
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, _image->getHeight());
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 32);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, _image->getWidth() * _image->getDepth() / 8 );
}
void GeoTiffWriter::write(IplImage* image, GeoTiffImage* tifImage)
{
TIFF *tif = 0;
tif = XTIFFOpen(_fileName, "w");
if (!tif) {
fprintf(stderr, "Can't create test TIFF file %s.\n", _fileName);
return;
}
setUpTIFFDirectory(tif);
double scale[3] = { 0.0, 0.0, 0.0 };
double pos[6] = { 0.0, 0.0,0.0,0.0, 0.0,0.0};
tifImage->getGeoScale(scale[0], scale[1], scale[2]);
tifImage->getGeoModelCoord(pos[3], pos[4], pos[5]);
TIFFSetField(tif, TIFFTAG_GEOPIXELSCALE, 3, scale);
TIFFSetField(tif, TIFFTAG_GEOTIEPOINTS, 6, pos);
// TIFFSetField(tif, TIFFTAG_GEOKEYDIRECTORY, 56, tifImage->getGeoKeyDirectory());
// TIFFSetField(tif, TIFFTAG_GEODOUBLEPARAMS, 4, tifImage->getGeoDoubleParams());
// TIFFSetField(tif, TIFFTAG_GEOASCIIPARAMS, tifImage->getGeoAsciiParams());
int bufSize = image->width * image->nChannels * image->depth / 8;
char* buf = (char*)malloc(bufSize);
for (int i = 0; i < image->height; i++)
{
memcpy(buf, image->imageData + bufSize * i, bufSize);
if (TIFFWriteScanline(tif, buf, i, 0) == -1)
{
fprintf(stderr, "Can't write image data.\n");
XTIFFClose(tif);
}
}
XTIFFClose(tif);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。