1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
38 //-------------------------------
40 //-------------------------------
45 #include "OSGConfig.h"
47 #include "OSGDBImageFileType.h"
48 #include "OSGGeoReferenceAttachment.h"
49 #include "OSGImageFunctions.h"
53 # define OSG_DB_ARG(ARG) ARG
55 # define OSG_DB_ARG(ARG)
58 # define OSG_DB_ARG(ARG) ARG
61 // Static Class Varible implementations:
62 static const OSG::Char8
*suffixArray
[] =
69 DBHeaderParameter::DBHeaderParameter(void) :
74 DBHeaderParameter::~DBHeaderParameter(void)
78 void DBHeaderParameter::setLastParam(void)
83 bool DBHeaderParameter::isLastParam(void)
89 DBHeaderIntParameter::DBHeaderIntParameter(UInt32
&uiParam
) :
95 DBHeaderIntParameter::~DBHeaderIntParameter(void)
99 void DBHeaderIntParameter::convert(const Char8
*str
)
103 sscanf(str
, "%u", &_uiParam
);
107 DBHeaderFloatParameter::DBHeaderFloatParameter(Real32
&rParam
) :
113 DBHeaderFloatParameter::~DBHeaderFloatParameter(void)
117 void DBHeaderFloatParameter::convert(const Char8
*str
)
121 sscanf(str
, "%f", &_rParam
);
125 DBHeader::DBHeader(void) :
166 std::string
szParamName("MAGIC");
168 _mParams
[szParamName
] = new DBHeaderIntParameter(uiMagic
);
170 szParamName
= "xsize";
172 _mParams
[szParamName
] = new DBHeaderIntParameter(uiXSize
);
174 szParamName
= "ysize";
176 _mParams
[szParamName
] = new DBHeaderIntParameter(uiYSize
);
178 szParamName
= "zsize";
180 _mParams
[szParamName
] = new DBHeaderIntParameter(uiZSize
);
182 szParamName
= "tsteps";
184 _mParams
[szParamName
] = new DBHeaderIntParameter(uiTSteps
);
186 szParamName
= "type";
188 _mParams
[szParamName
] = new DBHeaderIntParameter(uiType
);
194 _mParams
[szParamName
] = new DBHeaderFloatParameter(rSWx
);
198 _mParams
[szParamName
] = new DBHeaderFloatParameter(rSWy
);
202 _mParams
[szParamName
] = new DBHeaderFloatParameter(rNWx
);
206 _mParams
[szParamName
] = new DBHeaderFloatParameter(rNWy
);
212 _mParams
[szParamName
] = new DBHeaderFloatParameter(rNEx
);
216 _mParams
[szParamName
] = new DBHeaderFloatParameter(rNEy
);
220 _mParams
[szParamName
] = new DBHeaderFloatParameter(rSEx
);
224 _mParams
[szParamName
] = new DBHeaderFloatParameter(rSEy
);
230 _mParams
[szParamName
] = new DBHeaderFloatParameter(rH0
);
234 _mParams
[szParamName
] = new DBHeaderFloatParameter(rDh
);
238 _mParams
[szParamName
] = new DBHeaderFloatParameter(rT0
);
242 _mParams
[szParamName
] = new DBHeaderFloatParameter(rDt
);
246 szParamName
= "scaling";
248 _mParams
[szParamName
] = new DBHeaderFloatParameter(rScaling
);
250 szParamName
= "bias";
252 _mParams
[szParamName
] = new DBHeaderFloatParameter(rBias
);
256 szParamName
= "extformat";
258 _mParams
[szParamName
] = new DBHeaderIntParameter(uiExtFormat
);
260 szParamName
= "implformat";
262 _mParams
[szParamName
] = new DBHeaderIntParameter(uiImplFormat
);
266 szParamName
= "LLWGS84_swx";
268 _mParams
[szParamName
] = new DBHeaderFloatParameter(LLWGS84_rSWx
);
270 szParamName
= "LLWGS84_swy";
272 _mParams
[szParamName
] = new DBHeaderFloatParameter(LLWGS84_rSWy
);
274 szParamName
= "LLWGS84_nwx";
276 _mParams
[szParamName
] = new DBHeaderFloatParameter(LLWGS84_rNWx
);
278 szParamName
= "LLWGS84_nwy";
280 _mParams
[szParamName
] = new DBHeaderFloatParameter(LLWGS84_rNWy
);
284 szParamName
= "LLWGS84_nex";
286 _mParams
[szParamName
] = new DBHeaderFloatParameter(LLWGS84_rNEx
);
288 szParamName
= "LLWGS84_ney";
290 _mParams
[szParamName
] = new DBHeaderFloatParameter(LLWGS84_rNEy
);
292 szParamName
= "LLWGS84_sex";
294 _mParams
[szParamName
] = new DBHeaderFloatParameter(LLWGS84_rSEx
);
296 szParamName
= "LLWGS84_sey";
298 _mParams
[szParamName
] = new DBHeaderFloatParameter(LLWGS84_rSEy
);
302 szParamName
= "bytes";
304 _mParams
[szParamName
] = new DBHeaderIntParameter(uiBytes
);
306 _mParams
[szParamName
]->setLastParam();
309 DBHeader::~DBHeader(void)
311 ParameterMap::iterator mapIt
= _mParams
.begin();
312 ParameterMap::iterator mapEnd
= _mParams
.end ();
314 while(mapIt
!= mapEnd
)
316 delete mapIt
->second
;
322 bool DBHeader::read(FILE *pIn
)
324 bool returnValue
= true;
335 fgets(buffer
, 1024, pIn
);
337 strIt
= strtok(buffer
, "=");
341 ParameterMap::iterator mapIt
= _mParams
.find(std::string(strIt
));
343 if(mapIt
!= _mParams
.end())
345 bEnd
= mapIt
->second
->isLastParam();
347 strIt
= strtok(NULL
, "\n");
349 mapIt
->second
->convert(strIt
);
353 fprintf(stderr
, "Unknown parameter %s\n", strIt
);
362 buffer
[0] = fgetc(pIn
);
364 if(buffer
[0] != '\0')
366 fprintf(stderr
, "missing 0\n");
373 void DBHeader::dump(void) const
375 fprintf(stderr
, "MAGIC = %u\n", this->uiMagic
);
376 fprintf(stderr
, "xsize = %u\n", this->uiXSize
);
377 fprintf(stderr
, "ysize = %u\n", this->uiYSize
);
378 fprintf(stderr
, "zsize = %u\n", this->uiZSize
);
379 fprintf(stderr
, "tsteps = %u\n", this->uiTSteps
);
380 fprintf(stderr
, "type = %u\n", this->uiType
);
381 fprintf(stderr
, "swx = %f\n", this->rSWx
);
382 fprintf(stderr
, "swy = %f\n", this->rSWy
);
383 fprintf(stderr
, "nwx = %f\n", this->rNWx
);
384 fprintf(stderr
, "nwy = %f\n", this->rNWy
);
385 fprintf(stderr
, "nex = %f\n", this->rNEx
);
386 fprintf(stderr
, "ney = %f\n", this->rNEy
);
387 fprintf(stderr
, "sex = %f\n", this->rSEx
);
388 fprintf(stderr
, "sey = %f\n", this->rSEy
);
389 fprintf(stderr
, "h0 = %f\n", this->rDh
);
390 fprintf(stderr
, "dh = %f\n", this->rDh
);
391 fprintf(stderr
, "t0 = %f\n", this->rT0
);
392 fprintf(stderr
, "dt = %f\n", this->rDt
);
393 fprintf(stderr
, "scaling = %f\n", this->rScaling
);
394 fprintf(stderr
, "bias = %f\n", this->rBias
);
395 fprintf(stderr
, "extformat = %u\n", this->uiExtFormat
);
396 fprintf(stderr
, "implformat = %u\n", this->uiImplFormat
);
397 fprintf(stderr
, "LLWGS84_swx = %f\n", this->LLWGS84_rSWx
);
398 fprintf(stderr
, "LLWGS84_swy = %f\n", this->LLWGS84_rSWy
);
399 fprintf(stderr
, "LLWGS84_nwx = %f\n", this->LLWGS84_rNWx
);
400 fprintf(stderr
, "LLWGS84_nwy = %f\n", this->LLWGS84_rNWy
);
401 fprintf(stderr
, "LLWGS84_nex = %f\n", this->LLWGS84_rNEx
);
402 fprintf(stderr
, "LLWGS84_ney = %f\n", this->LLWGS84_rNEy
);
403 fprintf(stderr
, "LLWGS84_sex = %f\n", this->LLWGS84_rSEx
);
404 fprintf(stderr
, "LLWGS84_sey = %f\n", this->LLWGS84_rSEy
);
405 fprintf(stderr
, "bytes = %u\n", this->uiBytes
);
408 DBBlockAccessor::~DBBlockAccessor(void)
412 bool DBBlockAccessor::isOpen(void)
418 DBBlockAccessor::DBBlockAccessor(void) :
423 void DBBlockAccessor::open(const Char8
*szFilename
)
425 #ifdef OSG_WITH_GDALX
426 _pDataset
= (GDALDataset
*) GDALOpen(szFilename
, GA_ReadOnly
);
428 if(_pDataset
!= NULL
)
430 _pGeoRef
= GeoReferenceAttachment::create();
432 double adfGeoTransform
[6];
434 if(_pDataset
->GetGeoTransform(adfGeoTransform
) == CE_None
)
436 _pGeoRef
->editOrigin().setValues(adfGeoTransform
[0],
439 _pGeoRef
->editPixelSize().setValues(adfGeoTransform
[1],
442 if(GDALGetProjectionRef(_pDataset
) != NULL
)
444 OGRSpatialReferenceH hSRS
;
446 Char8
*szProjection
= (char *) GDALGetProjectionRef(_pDataset
);
448 hSRS
= OSRNewSpatialReference(NULL
);
450 if(OSRImportFromWkt(hSRS
, &szProjection
) == CE_None
)
452 _pGeoRef
->editEllipsoidAxis().setValues(
453 OSRGetSemiMajor(hSRS
, NULL
),
454 OSRGetSemiMinor(hSRS
, NULL
));
456 const Char8
*szDatum
= OSRGetAttrValue(hSRS
, "DATUM", 0);
458 if(szDatum
!= NULL
&& 0 == strcmp(szDatum
, "WGS_1984"))
460 _pGeoRef
->editDatum() =
461 GeoReferenceAttachment::WGS84
;
465 fprintf(stderr
, "Unknow datum %s\n",
468 _pGeoRef
->editDatum() =
469 GeoReferenceAttachment::UnknownDatum
;
473 OSRDestroySpatialReference(hSRS
);
477 int nBlockXSize
, nBlockYSize
;
478 int bGotMin
, bGotMax
;
481 _pBand
= _pDataset
->GetRasterBand(1);
483 _pBand
->GetBlockSize(&nBlockXSize
, &nBlockYSize
);
485 adfMinMax
[0] = _pBand
->GetMinimum(&bGotMin
);
486 adfMinMax
[1] = _pBand
->GetMaximum(&bGotMax
);
488 if(!(bGotMin
&& bGotMax
))
490 GDALComputeRasterMinMax((GDALRasterBandH
) _pBand
, TRUE
, adfMinMax
);
495 _eImgFormat
= Image::OSG_INVALID_PF
;
497 switch(_pDataset
->GetRasterCount())
500 _eImgFormat
= Image::OSG_L_PF
;
503 _eImgFormat
= Image::OSG_LA_PF
;
506 _eImgFormat
= Image::OSG_RGB_PF
;
509 _eImgFormat
= Image::OSG_RGBA_PF
;
513 _eImgType
= Image::OSG_INVALID_IMAGEDATATYPE
;
515 switch(_pBand
->GetRasterDataType())
518 _eImgType
= Image::OSG_UINT8_IMAGEDATA
;
522 _eImgType
= Image::OSG_UINT16_IMAGEDATA
;
526 _eImgType
= Image::OSG_INT16_IMAGEDATA
;
530 _eImgType
= Image::OSG_UINT32_IMAGEDATA
;
534 _eImgType
= Image::OSG_INT32_IMAGEDATA
;
538 _eImgType
= Image::OSG_FLOAT32_IMAGEDATA
;
547 GDALClose(_pDataset
);
553 _vSize
[0] = _pDataset
->GetRasterXSize();
554 _vSize
[1] = _pDataset
->GetRasterYSize();
556 _fNoDataValue
= _pBand
->GetNoDataValue();
558 _pGeoRef
->setNoDataValue(_fNoDataValue
);
564 bool DBBlockAccessor::readBlockA16(Vec2i vSampleOrigin
,
567 Int32 iTargetSizeBytes
)
569 #ifdef OSG_WITH_GDALX
574 UInt8
*pDst
= (UInt8
*) pTarget
;
576 Int32 xMin
= vSampleOrigin
.x();
577 Int32 xMax
= vSampleOrigin
.x() + iTextureSize
;
579 Int32 yMin
= vSampleOrigin
.y();
580 Int32 yMax
= vSampleOrigin
.y() + iTextureSize
;
582 for(UInt32 y
= yMin
; y
< yMax
; y
++)
584 for(UInt32 x
= xMin
; x
< xMax
; x
++)
586 for(UInt32 i
= 0; i
< 2; i
++)
594 destIdx
+= (iTextureSize
- (xMax
- xMin
)) * 2;
601 bool DBBlockAccessor::readBlockA16(Vec2i vSampleOrigin
,
604 Int32 iTargetSizeBytes
)
606 #ifdef OSG_WITH_GDALX
607 Int32 xMin
= vSampleOrigin
.x();
608 Int32 xMax
= vSampleOrigin
.x() + iTextureSize
;
610 Int32 yMin
= vSampleOrigin
.y();
611 Int32 yMax
= vSampleOrigin
.y() + iTextureSize
;
613 if(xMax
> _vSize
[0] || yMax
> _vSize
[1])
618 _vI16Buffer
.resize(iTextureSize
* iTextureSize
);
620 Int32 iSampleX
= osgMin(_vSize
[0] - vSampleOrigin
.x(), iTextureSize
);
621 Int32 iSampleY
= osgMin(_vSize
[1] - vSampleOrigin
.y(), iTextureSize
);
623 _pBand
->RasterIO(GF_Read
,
636 for(UInt32 y
= yMin
; y
< yMax
; y
++)
638 for(UInt32 x
= xMin
; x
< xMax
; x
++)
640 if(x
>= _vSize
[0] || y
>= _vSize
[1])
642 pTarget
[destIdx
] = Int16(_fNoDataValue
);
646 pTarget
[destIdx
] = _vI16Buffer
[srcIdx
];
657 _pBand
->RasterIO(GF_Read
,
675 /*! \class GDALImageFileType
677 Image File Type to read/write and store/restore Image objects as
678 GDAL (tif/tiff suffix) data.
680 To be able to load TIFF images you need the IJG TIFF library,
681 (check the Prerequisites page on www.opensg.org).
682 The lib comes with all Linux distributions.
684 You have to --enable-tif in the configure line to enable
685 the singleton object.
689 DBImageFileType
DBImageFileType:: _the("image/db",
692 (OSG_READ_SUPPORTED
));
695 //-------------------------------------------------------------------------
696 /*! Tries to fill the image object with the data read from
697 the given fileName. Returns true on success.
701 bool DBImageFileType::read( Image
*pImage
,
702 const Char8
*fileName
)
704 bool returnValue
= false;
706 FILE *pIn
= fopen(fileName
, "rb");
710 fprintf(stderr
, "db::open %p\n", pIn
);
714 returnValue
= oHeader
.read(pIn
);
716 if(returnValue
== false)
725 if(oHeader
.uiExtFormat
!= 0)
727 fprintf(stderr
, "ext == 0 only support");
736 Image::PixelFormat imagePf
= Image::OSG_RGBA_PF
;
737 Image::Type imageType
= Image::OSG_UINT8_IMAGEDATA
;
739 switch(oHeader
.uiType
)
742 imagePf
= Image::OSG_L_PF
;
743 imageType
= Image::OSG_UINT8_IMAGEDATA
;
746 imagePf
= Image::OSG_L_PF
;
747 imageType
= Image::OSG_INT16_IMAGEDATA
;
750 imagePf
= Image::OSG_L_PF
;
751 imageType
= Image::OSG_FLOAT32_IMAGEDATA
;
754 imagePf
= Image::OSG_RGB_PF
;
755 imageType
= Image::OSG_UINT8_IMAGEDATA
;
758 imagePf
= Image::OSG_RGBA_PF
;
759 imageType
= Image::OSG_UINT8_IMAGEDATA
;
762 imagePf
= Image::OSG_RGB_DXT1
;
763 imageType
= Image::OSG_UINT8_IMAGEDATA
;
766 imagePf
= Image::OSG_RGBA_DXT1
;
767 imageType
= Image::OSG_UINT8_IMAGEDATA
;
785 if(pImage
->getSize() == oHeader
.uiBytes
)
787 fread(pImage
->editData(),
792 #if BYTE_ORDER == LITTLE_ENDIAN
793 switch(oHeader
.uiType
)
796 swapAndConvertImageByteOrder
<
798 &clampMin
<Int16
, -100, 0> >(pImage
);
801 swapImageByteOrder
<Real32
>(pImage
);
808 if(oHeader
.uiXSize
!= 0 && oHeader
.uiYSize
!= 0)
810 if(oHeader
.LLWGS84_rSWx
!= 0.f
&&
811 oHeader
.LLWGS84_rSWy
!= 0.f
&&
812 oHeader
.LLWGS84_rNWx
!= 0.f
&&
813 oHeader
.LLWGS84_rNWy
!= 0.f
&&
814 oHeader
.LLWGS84_rNEx
!= 0.f
&&
815 oHeader
.LLWGS84_rNEy
!= 0.f
&&
816 oHeader
.LLWGS84_rSEx
!= 0.f
&&
817 oHeader
.LLWGS84_rSEy
!= 0.f
)
819 GeoReferenceAttachmentUnrecPtr pGeoRef
=
820 GeoReferenceAttachment::create();
822 pGeoRef
->setupWGS84Datum();
824 pGeoRef
->editOrigin().setValues(oHeader
.LLWGS84_rNWx
,
825 oHeader
.LLWGS84_rNWy
);
827 pGeoRef
->editPixelSize().setValues(
828 (oHeader
.LLWGS84_rSEx
-
829 oHeader
.LLWGS84_rNWx
) / oHeader
.uiXSize
,
830 (oHeader
.LLWGS84_rSEy
-
831 oHeader
.LLWGS84_rNWy
) / oHeader
.uiYSize
);
833 pImage
->addAttachment(pGeoRef
);
835 else if(oHeader
.rSWx
!= 0.f
&&
836 oHeader
.rSWy
!= 0.f
&&
837 oHeader
.rNWx
!= 0.f
&&
838 oHeader
.rNWy
!= 0.f
&&
839 oHeader
.rNEx
!= 0.f
&&
840 oHeader
.rNEy
!= 0.f
&&
841 oHeader
.rSEx
!= 0.f
&&
842 oHeader
.rSEy
!= 0.f
)
844 GeoReferenceAttachmentUnrecPtr pGeoRef
=
845 GeoReferenceAttachment::create();
847 pGeoRef
->setupWGS84Datum();
849 pGeoRef
->editOrigin().setValues(oHeader
.rNWx
,
852 pGeoRef
->editPixelSize().setValues(
853 (oHeader
.rSEx
- oHeader
.rNWx
) / oHeader
.uiXSize
,
854 (oHeader
.rSEy
- oHeader
.rNWy
) / oHeader
.uiYSize
);
856 pImage
->addAttachment(pGeoRef
);
862 fprintf(stderr
, "size mismatch %" PRISize
" %d\n",
874 #ifdef OSG_WITH_GDALX
876 GDALDataset
*pDataset
;
878 pDataset
= (GDALDataset
*) GDALOpen(fileName
, GA_ReadOnly
);
882 GeoReferenceAttachmentPtr pGeoRef
= GeoReferenceAttachment::create();
884 pImage
->addAttachment(pGeoRef
);
886 double adfGeoTransform
[6];
888 if(pDataset
->GetGeoTransform(adfGeoTransform
) == CE_None
)
890 pGeoRef
->editOrigin().setValues(adfGeoTransform
[0],
893 pGeoRef
->editPixelSize().setValues(adfGeoTransform
[1],
896 if(GDALGetProjectionRef(pDataset
) != NULL
)
898 OGRSpatialReferenceH hSRS
;
900 Char8
*szProjection
= (char *) GDALGetProjectionRef(pDataset
);
902 hSRS
= OSRNewSpatialReference(NULL
);
904 if(OSRImportFromWkt(hSRS
, &szProjection
) == CE_None
)
906 pGeoRef
->editEllipsoidAxis().setValues(
907 OSRGetSemiMajor(hSRS
, NULL
),
908 OSRGetSemiMinor(hSRS
, NULL
));
910 const Char8
*szDatum
= OSRGetAttrValue(hSRS
, "DATUM", 0);
912 if(szDatum
!= NULL
&& 0 == strcmp(szDatum
, "WGS_1984"))
914 pGeoRef
->editDatum() =
915 GeoReferenceAttachment::WGS84
;
919 fprintf(stderr
, "Unknow datum %s\n",
922 pGeoRef
->editDatum() =
923 GeoReferenceAttachment::UnknownDatum
;
927 OSRDestroySpatialReference(hSRS
);
931 GDALRasterBand
*pBand
;
932 int nBlockXSize
, nBlockYSize
;
933 int bGotMin
, bGotMax
;
936 pBand
= pDataset
->GetRasterBand( 1 );
937 pBand
->GetBlockSize( &nBlockXSize
, &nBlockYSize
);
939 adfMinMax
[0] = pBand
->GetMinimum( &bGotMin
);
940 adfMinMax
[1] = pBand
->GetMaximum( &bGotMax
);
942 if(!(bGotMin
&& bGotMax
))
943 GDALComputeRasterMinMax((GDALRasterBandH
) pBand
, TRUE
, adfMinMax
);
945 pBand
= pDataset
->GetRasterBand(1);
949 Image::PixelFormat ePF
= Image::OSG_INVALID_PF
;
951 switch(pDataset
->GetRasterCount())
954 ePF
= Image::OSG_L_PF
;
957 ePF
= Image::OSG_LA_PF
;
960 ePF
= Image::OSG_RGB_PF
;
963 ePF
= Image::OSG_RGBA_PF
;
967 Image::Type eDT
= Image::OSG_INVALID_IMAGEDATATYPE
;
969 switch(pBand
->GetRasterDataType())
972 eDT
= Image::OSG_UINT8_IMAGEDATA
;
976 eDT
= Image::OSG_UINT16_IMAGEDATA
;
980 eDT
= Image::OSG_INT16_IMAGEDATA
;
984 eDT
= Image::OSG_UINT32_IMAGEDATA
;
988 eDT
= Image::OSG_INT32_IMAGEDATA
;
992 eDT
= Image::OSG_FLOAT32_IMAGEDATA
;
1001 GDALClose(pDataset
);
1008 pDataset
->GetRasterXSize(),
1009 pDataset
->GetRasterYSize(),
1017 UChar8
*dst
= pImage
->editData();
1019 pBand
->RasterIO(GF_Read
,
1022 pDataset
->GetRasterXSize(),
1023 pDataset
->GetRasterYSize(),
1025 pDataset
->GetRasterXSize(),
1026 pDataset
->GetRasterYSize(),
1027 pBand
->GetRasterDataType(),
1031 pGeoRef
->setNoDataValue(pBand
->GetNoDataValue());
1036 GDALClose(pDataset
);
1040 #endif // OSG_WITH_GDAL
1043 //-------------------------------------------------------------------------
1044 /*! Tries to write the image object to the given output stream.
1045 Returns true on success.
1048 bool DBImageFileType::write(const Image
*OSG_DB_ARG(pImage
),
1049 const Char8
*OSG_DB_ARG(fileName
))
1051 bool retCode
= false;
1053 #ifdef OSG_WITH_GDALX
1054 if(pImage
->getDimension() < 1 || pImage
->getDimension() > 2)
1056 FWARNING(("TIFImageFileType::write: invalid dimension %d!\n",
1057 pImage
->getDimension()));
1062 TIFF
*out
= TIFFClientOpen("dummy", "wm", (thandle_t
)&os
,
1071 int lineSize
= pImage
->getWidth() * pImage
->getBpp();
1072 int photometric
= 0;
1073 int samplesPerPixel
= 0;
1077 // TODO: implement all cases correct
1078 switch(pImage
->getBpp())
1081 samplesPerPixel
= 1;
1082 photometric
= PHOTOMETRIC_MINISBLACK
;
1085 samplesPerPixel
= 2;
1086 photometric
= PHOTOMETRIC_MINISBLACK
;
1089 samplesPerPixel
= 3;
1090 photometric
= PHOTOMETRIC_RGB
;
1093 samplesPerPixel
= 4;
1094 photometric
= PHOTOMETRIC_RGB
;
1100 TIFFSetField(out
, TIFFTAG_IMAGEWIDTH
, pImage
->getWidth());
1101 TIFFSetField(out
, TIFFTAG_IMAGELENGTH
, pImage
->getHeight());
1102 TIFFSetField(out
, TIFFTAG_XRESOLUTION
, pImage
->getResX());
1103 TIFFSetField(out
, TIFFTAG_YRESOLUTION
, pImage
->getResY());
1104 TIFFSetField(out
, TIFFTAG_RESOLUTIONUNIT
, pImage
->getResUnit());
1105 TIFFSetField(out
, TIFFTAG_ORIENTATION
, ORIENTATION_TOPLEFT
);
1106 TIFFSetField(out
, TIFFTAG_SAMPLESPERPIXEL
, samplesPerPixel
);
1107 TIFFSetField(out
, TIFFTAG_BITSPERSAMPLE
, 8);
1108 TIFFSetField(out
, TIFFTAG_PLANARCONFIG
, PLANARCONFIG_CONTIG
);
1109 TIFFSetField(out
, TIFFTAG_PHOTOMETRIC
, photometric
);
1111 if(_options
.find("compressionType=LZW") != std::string::npos
)
1113 TIFFSetField(out
, TIFFTAG_COMPRESSION
, COMPRESSION_LZW
);
1117 TIFFSetField(out
, TIFFTAG_COMPRESSION
, COMPRESSION_NONE
);
1120 TIFFSetField(out
, TIFFTAG_ROWSPERSTRIP
, TIFFDefaultStripSize(out
, 0));
1122 for(row
= 0; row
< pImage
->getHeight(); row
++)
1126 ((pImage
->getHeight() - row
- 1) * lineSize
);
1128 if(TIFFWriteScanline(out
,
1129 (tdata_t
) const_cast<UChar8
*>(data
),
1143 SWARNING
<< getMimeType()
1144 << " write is not compiled into the current binary "
1151 bool DBImageFileType::validateHeader(const Char8
*fileName
, bool &implemented
)
1159 ImageBlockAccessorPtr
DBImageFileType::open(const Char8
*fileName
)
1161 DBBlockAccessorPtr
returnValue(new DBBlockAccessor
);
1163 returnValue
->open(fileName
);
1169 //-------------------------------------------------------------------------
1170 /*! Constructor used for the singleton object
1173 DBImageFileType::DBImageFileType(const Char8
*mimeType
,
1174 const Char8
*suffixArray
[],
1175 UInt16 suffixByteCount
,
1184 //-------------------------------------------------------------------------
1188 DBImageFileType::~DBImageFileType(void)