[ VIGRA Homepage | Class Index | Function Index | File Index | Main Page ]
![]() |
vigra/impex.hxx | ![]() |
---|
Go to the documentation of this file.
00001 /************************************************************************/ 00002 /* */ 00003 /* Copyright 2001-2002 by Gunnar Kedenburg */ 00004 /* Cognitive Systems Group, University of Hamburg, Germany */ 00005 /* */ 00006 /* This file is part of the VIGRA computer vision library. */ 00007 /* ( Version 1.2.0, Aug 07 2003 ) */ 00008 /* You may use, modify, and distribute this software according */ 00009 /* to the terms stated in the LICENSE file included in */ 00010 /* the VIGRA distribution. */ 00011 /* */ 00012 /* The VIGRA Website is */ 00013 /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ 00014 /* Please direct questions, bug reports, and contributions to */ 00015 /* koethe@informatik.uni-hamburg.de */ 00016 /* */ 00017 /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ 00018 /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */ 00019 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ 00020 /* */ 00021 /************************************************************************/ 00022 00023 /*! 00024 \file impex.hxx 00025 \brief image import and export functions 00026 00027 this file provides the declarations and implementations of importImage() 00028 and exportImage(). the matching implementation for the given datatype is 00029 selected by template metacode. 00030 */ 00031 00032 #ifndef VIGRA_IMPEX_HXX 00033 #define VIGRA_IMPEX_HXX 00034 00035 #if defined(_MSC_VER) 00036 #pragma warning (disable: 4267) 00037 #endif 00038 00039 #include "vigra/stdimage.hxx" 00040 #include "vigra/tinyvector.hxx" 00041 #include "vigra/imageinfo.hxx" 00042 #include "vigra/numerictraits.hxx" 00043 #include "vigra/codec.hxx" 00044 #include "vigra/accessor.hxx" 00045 #include "vigra/inspectimage.hxx" 00046 #include "vigra/transformimage.hxx" 00047 #include "vigra/copyimage.hxx" 00048 00049 // TODO 00050 // next refactoring: pluggable conversion algorithms 00051 00052 namespace vigra 00053 { 00054 /** \addtogroup VigraImpex 00055 **/ 00056 //@{ 00057 00058 /*! 00059 \brief used for reading bands after the source data type has been figured out. 00060 00061 <b>\#include</b> "<a href="impex_8hxx-source.html">vigra/impex.hxx</a>"<br> 00062 Namespace: vigra 00063 00064 <b> Declaration:</b> 00065 00066 \code 00067 namespace vigra { 00068 template< class ImageIterator, class Accessor, class SrcValueType > 00069 void read_bands( Decoder * dec, ImageIterator ys, Accessor a, SrcValueType ) 00070 } 00071 \endcode 00072 00073 \param dec decoder object through which the source data will be accessed 00074 \param ys image iterator referencing the upper left pixel of the destination image 00075 \param a image accessor for the destination image 00076 */ 00077 template< class ImageIterator, class Accessor, class SrcValueType > 00078 void read_bands( Decoder * dec, ImageIterator ys, Accessor a, SrcValueType ) 00079 { 00080 typedef unsigned int size_type; 00081 typedef typename ImageIterator::row_iterator DstRowIterator; 00082 typedef typename Accessor::value_type AccessorValueType; 00083 typedef typename AccessorValueType::value_type DstValueType; 00084 00085 const size_type width = dec->getWidth(); 00086 const size_type height = dec->getHeight(); 00087 const size_type num_bands = dec->getNumBands(); 00088 00089 SrcValueType const * scanline; 00090 DstRowIterator xs; 00091 00092 // iterate 00093 for( size_type y = 0; y < height; ++y, ++ys.y ) { 00094 dec->nextScanline(); 00095 for( size_type b = 0; b < num_bands; ++b ) { 00096 xs = ys.rowIterator(); 00097 scanline = static_cast< SrcValueType const * > 00098 (dec->currentScanlineOfBand(b)); 00099 for( size_type x = 0; x < width; ++x, ++xs ) { 00100 a.setComponent( *scanline, xs, b ); 00101 scanline += dec->getOffset(); 00102 } 00103 } 00104 } 00105 } // read_bands() 00106 00107 /*! 00108 \brief used for reading bands after the source data type has been figured out. 00109 00110 <b>\#include</b> "<a href="impex_8hxx-source.html">vigra/impex.hxx</a>"<br> 00111 Namespace: vigra 00112 00113 <b> Declaration:</b> 00114 00115 \code 00116 namespace vigra { 00117 template< class ImageIterator, class Accessor, class SrcValueType > 00118 void read_band( Decoder * dec, ImageIterator ys, Accessor a, SrcValueType ) 00119 } 00120 \endcode 00121 00122 \param dec decoder object through which the source data will be accessed 00123 \param ys image iterator referencing the upper left pixel of the destination image 00124 \param a image accessor for the destination image 00125 */ 00126 template< class ImageIterator, class Accessor, class SrcValueType > 00127 void read_band( Decoder * dec, ImageIterator ys, Accessor a, SrcValueType ) 00128 { 00129 typedef unsigned int size_type; 00130 typedef typename ImageIterator::row_iterator DstRowIterator; 00131 typedef typename Accessor::value_type DstValueType; 00132 const size_type width = dec->getWidth(); 00133 const size_type height = dec->getHeight(); 00134 00135 SrcValueType const * scanline; 00136 DstRowIterator xs; 00137 00138 for( size_type y = 0; y < height; ++y, ++ys.y ) { 00139 dec->nextScanline(); 00140 xs = ys.rowIterator(); 00141 scanline = static_cast< SrcValueType const * >(dec->currentScanlineOfBand(0)); 00142 for( size_type x = 0; x < width; ++x, ++xs ) 00143 a.set( scanline[x], xs ); 00144 } 00145 } // read_band() 00146 00147 /*! 00148 \brief used for reading images of vector type, such as integer of float rgb. 00149 00150 <b>\#include</b> "<a href="impex_8hxx-source.html">vigra/impex.hxx</a>"<br> 00151 Namespace: vigra 00152 00153 <b> Declaration:</b> 00154 00155 \code 00156 namespace vigra { 00157 template< class ImageIterator, class Accessor > 00158 void importVectorImage( const ImageImportInfo & info, ImageIterator iter, Accessor a ) 00159 } 00160 \endcode 00161 00162 \param ImageIterator the image iterator type for the destination image 00163 \param Accessor the image accessor type for the destination image 00164 \param info user supplied image import information 00165 \param iter image iterator referencing the upper left pixel of the destination image 00166 \param a image accessor for the destination image 00167 */ 00168 template< class ImageIterator, class Accessor > 00169 void importVectorImage( const ImageImportInfo & info, ImageIterator iter, Accessor a ) 00170 { 00171 std::auto_ptr<Decoder> dec = decoder(info); 00172 std::string pixeltype = dec->getPixelType(); 00173 00174 if ( pixeltype == "UINT8" ) 00175 read_bands( dec.get(), iter, a, (unsigned char)0 ); 00176 else if ( pixeltype == "INT16" ) 00177 read_bands( dec.get(), iter, a, short() ); 00178 else if ( pixeltype == "INT32" ) 00179 read_bands( dec.get(), iter, a, int() ); 00180 else if ( pixeltype == "FLOAT" ) 00181 read_bands( dec.get(), iter, a, float() ); 00182 else if ( pixeltype == "DOUBLE" ) 00183 read_bands( dec.get(), iter, a, double() ); 00184 else 00185 vigra_precondition( false, "invalid pixeltype" ); 00186 00187 // close the decoder 00188 dec->close(); 00189 } 00190 00191 /*! 00192 \brief used for reading images of scalar type, such as integer and float grayscale. 00193 00194 <b>\#include</b> "<a href="impex_8hxx-source.html">vigra/impex.hxx</a>"<br> 00195 Namespace: vigra 00196 00197 <b> Declaration:</b> 00198 00199 \code 00200 namespace vigra { 00201 template < class ImageIterator, class Accessor > 00202 void importScalarImage( const ImageImportInfo & info, ImageIterator iter, Accessor a ) 00203 } 00204 \endcode 00205 00206 \param ImageIterator the image iterator type for the destination image 00207 \param Accessor the image accessor type for the destination image 00208 \param info user supplied image import information 00209 \param iter image iterator referencing the upper left pixel of the destination image 00210 \param a image accessor for the destination image 00211 */ 00212 template < class ImageIterator, class Accessor > 00213 void importScalarImage( const ImageImportInfo & info, ImageIterator iter, Accessor a ) 00214 { 00215 std::auto_ptr<Decoder> dec = decoder(info); 00216 std::string pixeltype = dec->getPixelType(); 00217 00218 if ( pixeltype == "UINT8" ) 00219 read_band( dec.get(), iter, a, (unsigned char)0 ); 00220 else if ( pixeltype == "INT16" ) 00221 read_band( dec.get(), iter, a, short() ); 00222 else if ( pixeltype == "INT32" ) 00223 read_band( dec.get(), iter, a, int() ); 00224 else if ( pixeltype == "FLOAT" ) 00225 read_band( dec.get(), iter, a, float() ); 00226 else if ( pixeltype == "DOUBLE" ) 00227 read_band( dec.get(), iter, a, double() ); 00228 else 00229 vigra_precondition( false, "invalid pixeltype" ); 00230 00231 // close the decoder 00232 dec->close(); 00233 } 00234 00235 template < class ImageIterator, class Accessor > 00236 void importImage( const ImageImportInfo & info, ImageIterator iter, Accessor a, VigraFalseType ) 00237 { 00238 importVectorImage( info, iter, a ); 00239 } 00240 00241 template < class ImageIterator, class Accessor > 00242 void importImage( const ImageImportInfo & info, ImageIterator iter, Accessor a, VigraTrueType ) 00243 { 00244 importScalarImage( info, iter, a ); 00245 } 00246 00247 /********************************************************/ 00248 /* */ 00249 /* importImage */ 00250 /* */ 00251 /********************************************************/ 00252 00253 /** \brief Read an image, given an \ref vigra::ImageImportInfo object. 00254 00255 <b> Declarations:</b> 00256 00257 pass arguments explicitly: 00258 \code 00259 namespace vigra { 00260 template <class ImageIterator, class Accessor> 00261 void 00262 importImage(ImageImportInfo const & image, ImageIterator iter, Accessor a) 00263 } 00264 \endcode 00265 00266 use argument objects in conjuction with \ref ArgumentObjectFactories: 00267 \code 00268 namespace vigra { 00269 template <class ImageIterator, class Accessor> 00270 inline void 00271 importImage(ImageImportInfo const & image, pair<ImageIterator, Accessor> dest) 00272 } 00273 \endcode 00274 00275 <b> Usage:</b> 00276 00277 <b>\#include</b> "<a href="impex_8hxx-source.html">vigra/impex.hxx</a>"<br> 00278 Namespace: vigra 00279 00280 \code 00281 00282 vigra::ImageImportInfo info("myimage.gif"); 00283 00284 if(info.isGrayscale()) 00285 { 00286 // create byte image of appropriate size 00287 vigra::BImage in(info.width(), info.height()); 00288 00289 vigra::importImage(info, destImage(in)); // read the image 00290 ... 00291 } 00292 else 00293 { 00294 // create byte RGB image of appropriate size 00295 vigra::BRGBImage in(info.width(), info.height()); 00296 00297 vigra::importImage(info, destImage(in)); // read the image 00298 ... 00299 } 00300 00301 \endcode 00302 00303 <b> Preconditions:</b> 00304 00305 <UL> 00306 00307 <LI> the image file must be readable 00308 <LI> the file type must be one of 00309 00310 <DL> 00311 <DT>"BMP"<DD> Microsoft Windows bitmap image file. 00312 <DT>"GIF"<DD> CompuServe graphics interchange format; 8-bit color. 00313 <DT>"JPEG"<DD> Joint Photographic Experts Group JFIF format; compressed 24-bit color. (only available if libjpeg is installed) 00314 <DT>"PNG"<DD> Portable Network Graphic. (only available if libpng is installed) 00315 <DT>"PBM"<DD> Portable bitmap format (black and white). 00316 <DT>"PGM"<DD> Portable graymap format (gray scale). 00317 <DT>"PNM"<DD> Portable anymap. 00318 <DT>"PPM"<DD> Portable pixmap format (color). 00319 <DT>"SUN"<DD> SUN Rasterfile. 00320 <DT>"TIFF"<DD> Tagged Image File Format. (only available if libtiff is installed.) 00321 <DT>"VIFF"<DD> Khoros Visualization image file. 00322 </DL> 00323 </UL> 00324 **/ 00325 template < class ImageIterator, class Accessor > 00326 void importImage( const ImageImportInfo & info, ImageIterator iter, Accessor a ) 00327 { 00328 typedef typename NumericTraits<typename Accessor::value_type>::isScalar is_scalar; 00329 importImage( info, iter, a, is_scalar() ); 00330 } 00331 00332 template < class ImageIterator, class Accessor > 00333 void importImage( const ImageImportInfo & info, pair< ImageIterator, Accessor > dest ) 00334 { 00335 importImage( info, dest.first, dest.second ); 00336 } 00337 00338 /*! 00339 \brief used for writing bands after the source data type has been figured out. 00340 00341 <b>\#include</b> "<a href="impex_8hxx-source.html">vigra/impex.hxx</a>"<br> 00342 Namespace: vigra 00343 00344 <b> Declaration:</b> 00345 00346 \code 00347 namespace vigra { 00348 template< class ImageIterator, class Accessor, class DstValueType > 00349 void write_bands( Encoder * enc, ImageIterator ul, ImageIterator lr, Accessor a, DstValueType ) 00350 } 00351 \endcode 00352 00353 \param enc encoder object through which the destination data will be accessed 00354 \param ul image iterator referencing the upper left pixel of the source image 00355 \param lr image iterator referencing the lower right pixel of the source image 00356 \param a image accessor for the source image 00357 */ 00358 template< class ImageIterator, class Accessor, class DstValueType > 00359 void write_bands( Encoder * enc, ImageIterator ul, ImageIterator lr, Accessor a, DstValueType) 00360 { 00361 typedef unsigned int size_type; 00362 typedef typename ImageIterator::row_iterator SrcRowIterator; 00363 typedef typename Accessor::value_type AccessorValueType; 00364 typedef typename AccessorValueType::value_type SrcValueType; 00365 00366 // complete decoder settings 00367 const size_type width = lr.x - ul.x; 00368 const size_type height = lr.y - ul.y; 00369 enc->setWidth(width); 00370 enc->setHeight(height); 00371 const size_type num_bands = a(ul).size(); 00372 enc->setNumBands(num_bands); 00373 enc->finalizeSettings(); 00374 00375 SrcRowIterator xs; 00376 DstValueType * scanline; 00377 00378 // iterate 00379 ImageIterator ys(ul); 00380 for( size_type y = 0; y < height; ++y, ++ys.y ) { 00381 for( size_type b = 0; b < num_bands; ++b ) { 00382 xs = ys.rowIterator(); 00383 scanline = static_cast< DstValueType * > 00384 (enc->currentScanlineOfBand(b)); 00385 for( size_type x = 0; x < width; ++x, ++xs ) { 00386 *scanline = a.getComponent( xs, b ); 00387 scanline += enc->getOffset(); 00388 } 00389 } 00390 enc->nextScanline(); 00391 } 00392 } // write_bands() 00393 00394 /*! 00395 \brief used for writing bands after the source data type has been figured out. 00396 00397 <b>\#include</b> "<a href="impex_8hxx-source.html">vigra/impex.hxx</a>"<br> 00398 Namespace: vigra 00399 00400 <b> Declaration:</b> 00401 00402 \code 00403 namespace vigra { 00404 template< class ImageIterator, class Accessor, class DstValueType > 00405 void write_band( Encoder * enc, ImageIterator ul, ImageIterator lr, Accessor a, DstValueType ) 00406 } 00407 \endcode 00408 00409 \param enc encoder object through which the destination data will be accessed 00410 \param ul image iterator referencing the upper left pixel of the source image 00411 \param lr image iterator referencing the lower right pixel of the source image 00412 \param a image accessor for the source image 00413 */ 00414 template< class ImageIterator, class Accessor, class DstValueType > 00415 void write_band( Encoder * enc, ImageIterator ul, ImageIterator lr, Accessor a, DstValueType) 00416 { 00417 typedef unsigned int size_type; 00418 typedef typename ImageIterator::row_iterator SrcRowIterator; 00419 typedef typename Accessor::value_type SrcValueType; 00420 00421 // complete decoder settings 00422 const size_type width = lr.x - ul.x; 00423 const size_type height = lr.y - ul.y; 00424 enc->setWidth(width); 00425 enc->setHeight(height); 00426 enc->setNumBands(1); 00427 enc->finalizeSettings(); 00428 00429 SrcRowIterator xs; 00430 DstValueType * scanline; 00431 00432 // iterate 00433 ImageIterator ys(ul); 00434 size_type y; 00435 for( y = 0; y < height; ++y, ++ys.y ) { 00436 xs = ys.rowIterator(); 00437 scanline = static_cast< DstValueType * >(enc->currentScanlineOfBand(0)); 00438 for( size_type x = 0; x < width; ++x, ++xs, ++scanline ) 00439 *scanline = a(xs); 00440 enc->nextScanline(); 00441 } 00442 } // write_band() 00443 00444 template < class SrcIterator, class SrcAccessor, 00445 class DestIterator, class DestAccessor > 00446 void mapVectorImageToByteImage( SrcIterator sul, SrcIterator slr, SrcAccessor sget, 00447 DestIterator dul, DestAccessor dget ) 00448 { 00449 typedef typename SrcAccessor::value_type SrcValue; 00450 typedef typename SrcValue::value_type SrcComponent; 00451 typedef typename NumericTraits<SrcValue>::RealPromote PromoteValue; 00452 typedef typename PromoteValue::value_type PromoteComponent; 00453 00454 vigra::FindMinMax<SrcComponent> minmax; 00455 vigra::inspectImage( sul, slr, sget, minmax ); 00456 const PromoteComponent scale = 255.0 / (minmax.max - minmax.min); 00457 const PromoteValue offset( -minmax.min, -minmax.min, -minmax.min ); 00458 vigra::transformImage( sul, slr, sget, dul, dget, 00459 linearIntensityTransform( scale, offset ) ); 00460 } 00461 00462 template < class SrcIterator, class SrcAccessor, 00463 class DestIterator, class DestAccessor > 00464 void mapScalarImageToByteImage( SrcIterator sul, SrcIterator slr, SrcAccessor sget, 00465 DestIterator dul, DestAccessor dget ) 00466 { 00467 typedef typename SrcAccessor::value_type SrcValue; 00468 typedef typename NumericTraits<SrcValue>::RealPromote PromoteValue; 00469 00470 vigra::FindMinMax<SrcValue> minmax; 00471 vigra::inspectImage( sul, slr, sget, minmax ); 00472 const PromoteValue scale = 255.0 / (minmax.max - minmax.min); 00473 const PromoteValue offset = -minmax.min; 00474 vigra::transformImage( sul, slr, sget, dul, dget, 00475 linearIntensityTransform( scale, offset ) ); 00476 } 00477 00478 /*! 00479 \brief used for writing images of floating point vector type, such as floating point rgb. 00480 00481 <b>\#include</b> "<a href="impex_8hxx-source.html">vigra/impex.hxx</a>"<br> 00482 Namespace: vigra 00483 00484 <b> Declaration:</b> 00485 00486 \code 00487 namespace vigra { 00488 template < class SrcIterator, class SrcAccessor > 00489 void exportFloatingVectorImage( SrcIterator sul, SrcIterator slr, SrcAccessor sget, 00490 const ImageExportInfo & info ) 00491 } 00492 \endcode 00493 00494 \param SrcIterator the image iterator type for the source image 00495 \param SrcAccessor the image accessor type for the source image 00496 \param sul image iterator referencing the upper left pixel of the source image 00497 \param slr image iterator referencing the lower right pixel of the source image 00498 \param sget image accessor for the source image 00499 \param info user supplied image export information 00500 */ 00501 template < class SrcIterator, class SrcAccessor > 00502 void exportFloatingVectorImage( SrcIterator sul, SrcIterator slr, SrcAccessor sget, 00503 const ImageExportInfo & info ) 00504 { 00505 typedef typename SrcAccessor::value_type AccessorValueType; 00506 typedef typename AccessorValueType::value_type SrcValueType; 00507 00508 std::auto_ptr<Encoder> enc = encoder(info); 00509 00510 switch(sizeof(SrcValueType)) { 00511 case 4: 00512 // pixel type is float 00513 if ( isPixelTypeSupported( enc->getFileType(), "FLOAT" ) ) { 00514 enc->setPixelType( "FLOAT" ); 00515 write_bands( enc.get(), sul, slr, sget, float() ); 00516 } else { 00517 // convert to unsigned char in the usual way 00518 enc->setPixelType( "UINT8" ); 00519 vigra::BRGBImage image(slr-sul); 00520 mapVectorImageToByteImage(sul, slr, sget, image.upperLeft(), image.accessor()); 00521 write_bands( enc.get(), image.upperLeft(), 00522 image.lowerRight(), image.accessor(), (unsigned char)0 ); 00523 } 00524 break; 00525 case 8: 00526 // pixel type is double 00527 if ( isPixelTypeSupported( enc->getFileType(), "DOUBLE" ) ) { 00528 enc->setPixelType( "DOUBLE" ); 00529 write_bands( enc.get(), sul, slr, sget, double() ); 00530 } else { 00531 // convert to unsigned char in the usual way 00532 enc->setPixelType( "UINT8" ); 00533 vigra::BRGBImage image(slr-sul); 00534 mapVectorImageToByteImage(sul, slr, sget, image.upperLeft(), image.accessor()); 00535 write_bands( enc.get(), image.upperLeft(), 00536 image.lowerRight(), image.accessor(), (unsigned char)0 ); 00537 } 00538 break; 00539 default: 00540 vigra_precondition( false, "unsupported floating point size" ); 00541 } 00542 00543 // close the encoder 00544 enc->close(); 00545 } 00546 00547 /*! 00548 \brief used for writing images of integral vector type, such as integer rgb. 00549 00550 <b>\#include</b> "<a href="impex_8hxx-source.html">vigra/impex.hxx</a>"<br> 00551 Namespace: vigra 00552 00553 <b> Declaration:</b> 00554 00555 \code 00556 namespace vigra { 00557 template < class SrcIterator, class SrcAccessor > 00558 void exportIntegralVectorImage( SrcIterator sul, SrcIterator slr, SrcAccessor sget, 00559 const ImageExportInfo & info ) 00560 } 00561 \endcode 00562 00563 \param SrcIterator the image iterator type for the source image 00564 \param SrcAccessor the image accessor type for the source image 00565 \param sul image iterator referencing the upper left pixel of the source image 00566 \param slr image iterator referencing the lower right pixel of the source image 00567 \param sget image accessor for the source image 00568 \param info user supplied image export information 00569 */ 00570 template < class SrcIterator, class SrcAccessor > 00571 void exportIntegralVectorImage( SrcIterator sul, SrcIterator slr, SrcAccessor sget, 00572 const ImageExportInfo & info ) 00573 { 00574 typedef typename SrcAccessor::value_type AccessorValueType; 00575 typedef typename AccessorValueType::value_type SrcValueType; 00576 00577 std::auto_ptr<Encoder> enc = encoder(info); 00578 00579 switch(sizeof(SrcValueType)) { 00580 case 1: 00581 enc->setPixelType( "UINT8" ); 00582 write_bands( enc.get(), sul, slr, sget, (unsigned char)0 ); 00583 break; 00584 case 2: 00585 if ( isPixelTypeSupported( enc->getFileType(), "INT16" ) ) { 00586 enc->setPixelType( "INT16" ); 00587 write_bands( enc.get(), sul, slr, sget, short() ); 00588 } else { 00589 // convert to unsigned char in the usual way 00590 enc->setPixelType( "UINT8" ); 00591 vigra::BRGBImage image(slr-sul); 00592 mapVectorImageToByteImage(sul, slr, sget, image.upperLeft(), image.accessor()); 00593 write_bands( enc.get(), image.upperLeft(), 00594 image.lowerRight(), image.accessor(), (unsigned char)0 ); 00595 } 00596 break; 00597 case 4: 00598 if ( isPixelTypeSupported( enc->getFileType(), "INT32" ) ) { 00599 enc->setPixelType( "INT32" ); 00600 write_bands( enc.get(), sul, slr, sget, int() ); 00601 } else { 00602 // convert to unsigned char in the usual way 00603 enc->setPixelType( "UINT8" ); 00604 vigra::BRGBImage image(slr-sul); 00605 mapVectorImageToByteImage(sul, slr, sget, image.upperLeft(), image.accessor()); 00606 write_bands( enc.get(), image.upperLeft(), 00607 image.lowerRight(), image.accessor(), (unsigned char)0 ); 00608 } 00609 break; 00610 default: 00611 vigra_precondition( false, "unsupported integer size" ); 00612 } 00613 00614 // close the encoder 00615 enc->close(); 00616 } 00617 00618 /*! 00619 \brief used for writing images of floating point scalar type, such as floating point grayscale. 00620 00621 <b>\#include</b> "<a href="impex_8hxx-source.html">vigra/impex.hxx</a>"<br> 00622 Namespace: vigra 00623 00624 <b> Declaration:</b> 00625 00626 \code 00627 namespace vigra { 00628 template < class SrcIterator, class SrcAccessor > 00629 void exportFloatingScalarImage( SrcIterator sul, SrcIterator slr, SrcAccessor sget, 00630 const ImageExportInfo & info ) 00631 } 00632 \endcode 00633 00634 \param SrcIterator the image iterator type for the source image 00635 \param SrcAccessor the image accessor type for the source image 00636 \param sul image iterator referencing the upper left pixel of the source image 00637 \param slr image iterator referencing the lower right pixel of the source image 00638 \param sget image accessor for the source image 00639 \param info user supplied image export information 00640 */ 00641 template < class SrcIterator, class SrcAccessor > 00642 void exportFloatingScalarImage( SrcIterator sul, SrcIterator slr, SrcAccessor sget, 00643 const ImageExportInfo & info ) 00644 { 00645 typedef typename SrcAccessor::value_type SrcValueType; 00646 00647 std::auto_ptr<Encoder> enc = encoder(info); 00648 00649 switch(sizeof(SrcValueType)) { 00650 case 4: 00651 // pixel type is float 00652 if ( isPixelTypeSupported( enc->getFileType(), "FLOAT" ) ) { 00653 enc->setPixelType( "FLOAT" ); 00654 write_band( enc.get(), sul, slr, sget, float() ); 00655 } else { 00656 // convert to unsigned char in the usual way 00657 enc->setPixelType( "UINT8" ); 00658 vigra::BImage image(slr-sul); 00659 mapScalarImageToByteImage(sul, slr, sget, image.upperLeft(), image.accessor()); 00660 write_band( enc.get(), image.upperLeft(), 00661 image.lowerRight(), image.accessor(), (unsigned char)0 ); 00662 } 00663 break; 00664 case 8: 00665 // pixel type is double 00666 if ( isPixelTypeSupported( enc->getFileType(), "DOUBLE" ) ) { 00667 enc->setPixelType( "DOUBLE" ); 00668 write_band( enc.get(), sul, slr, sget, double() ); 00669 } else { 00670 // convert to unsigned char in the usual way 00671 enc->setPixelType( "UINT8" ); 00672 vigra::BImage image(slr-sul); 00673 mapScalarImageToByteImage(sul, slr, sget, image.upperLeft(), image.accessor()); 00674 write_band( enc.get(), image.upperLeft(), 00675 image.lowerRight(), image.accessor(), (unsigned char)0 ); 00676 } 00677 break; 00678 default: 00679 vigra_precondition( false, "unsupported floating point size" ); 00680 } 00681 00682 // close the encoder 00683 enc->close(); 00684 } 00685 00686 /*! 00687 \brief used for writing images of integral scalar type, such as integer grayscale. 00688 00689 <b>\#include</b> "<a href="impex_8hxx-source.html">vigra/impex.hxx</a>"<br> 00690 Namespace: vigra 00691 00692 <b> Declaration:</b> 00693 00694 \code 00695 namespace vigra { 00696 template < class SrcIterator, class SrcAccessor > 00697 void exportIntegralScalarImage( SrcIterator sul, SrcIterator slr, SrcAccessor sget, 00698 const ImageExportInfo & info ) 00699 } 00700 \endcode 00701 00702 \param SrcIterator the image iterator type for the source image 00703 \param SrcAccessor the image accessor type for the source image 00704 \param sul image iterator referencing the upper left pixel of the source image 00705 \param slr image iterator referencing the lower right pixel of the source image 00706 \param sget image accessor for the source image 00707 \param info user supplied image export information 00708 */ 00709 template < class SrcIterator, class SrcAccessor > 00710 void exportIntegralScalarImage( SrcIterator sul, SrcIterator slr, SrcAccessor sget, 00711 const ImageExportInfo & info ) 00712 { 00713 typedef typename SrcAccessor::value_type SrcValueType; 00714 00715 std::auto_ptr<Encoder> enc = encoder(info); 00716 00717 switch(sizeof(SrcValueType)) { 00718 case 1: 00719 enc->setPixelType( "UINT8" ); 00720 write_band( enc.get(), sul, slr, sget, (unsigned char)0 ); 00721 break; 00722 case 2: 00723 if ( isPixelTypeSupported( enc->getFileType(), "INT16" ) ) { 00724 enc->setPixelType( "INT16" ); 00725 write_band( enc.get(), sul, slr, sget, short() ); 00726 } else { 00727 // convert to unsigned char in the usual way 00728 enc->setPixelType( "UINT8" ); 00729 vigra::BImage image(slr-sul); 00730 mapScalarImageToByteImage(sul, slr, sget, image.upperLeft(), image.accessor()); 00731 write_band( enc.get(), image.upperLeft(), 00732 image.lowerRight(), image.accessor(), (unsigned char)0 ); 00733 } 00734 break; 00735 case 4: 00736 if ( isPixelTypeSupported( enc->getFileType(), "INT32" ) ) { 00737 enc->setPixelType( "INT32" ); 00738 write_band( enc.get(), sul, slr, sget, int() ); 00739 } else { 00740 // convert to unsigned char in the usual way 00741 enc->setPixelType( "UINT8" ); 00742 vigra::BImage image(slr-sul); 00743 mapScalarImageToByteImage(sul, slr, sget, image.upperLeft(), image.accessor()); 00744 write_band( enc.get(), image.upperLeft(), 00745 image.lowerRight(), image.accessor(), (unsigned char)0 ); 00746 } 00747 break; 00748 default: 00749 vigra_precondition( false, "unsupported integer size" ); 00750 } 00751 00752 // close the encoder 00753 enc->close(); 00754 } 00755 00756 template < class SrcIterator, class SrcAccessor > 00757 inline 00758 void exportVectorImage( SrcIterator sul, SrcIterator slr, SrcAccessor sget, 00759 const ImageExportInfo & info, VigraFalseType ) 00760 { 00761 exportFloatingVectorImage( sul, slr, sget, info ); 00762 } 00763 00764 template < class SrcIterator, class SrcAccessor > 00765 inline 00766 void exportVectorImage( SrcIterator sul, SrcIterator slr, SrcAccessor sget, 00767 const ImageExportInfo & info, VigraTrueType ) 00768 { 00769 exportIntegralVectorImage( sul, slr, sget, info ); 00770 } 00771 00772 template < class SrcIterator, class SrcAccessor > 00773 inline 00774 void exportVectorImage( SrcIterator sul, SrcIterator slr, SrcAccessor sget, 00775 const ImageExportInfo & info ) 00776 { 00777 typedef typename NumericTraits<typename SrcAccessor::value_type>::isIntegral is_integral; 00778 exportVectorImage( sul, slr, sget, info, is_integral() ); 00779 } 00780 00781 template < class SrcIterator, class SrcAccessor > 00782 inline 00783 void exportScalarImage( SrcIterator sul, SrcIterator slr, SrcAccessor sget, 00784 const ImageExportInfo & info, VigraFalseType ) 00785 { 00786 exportFloatingScalarImage( sul, slr, sget, info ); 00787 } 00788 00789 template < class SrcIterator, class SrcAccessor > 00790 inline 00791 void exportScalarImage( SrcIterator sul, SrcIterator slr, SrcAccessor sget, 00792 const ImageExportInfo & info, VigraTrueType ) 00793 { 00794 exportIntegralScalarImage( sul, slr, sget, info ); 00795 } 00796 00797 template < class SrcIterator, class SrcAccessor > 00798 inline 00799 void exportScalarImage( SrcIterator sul, SrcIterator slr, SrcAccessor sget, 00800 const ImageExportInfo & info ) 00801 { 00802 typedef typename NumericTraits<typename SrcAccessor::value_type>::isIntegral is_integral; 00803 exportScalarImage( sul, slr, sget, info, is_integral() ); 00804 } 00805 00806 template < class SrcIterator, class SrcAccessor > 00807 inline 00808 void exportImage( SrcIterator sul, SrcIterator slr, SrcAccessor sget, 00809 const ImageExportInfo & info, VigraFalseType ) 00810 { 00811 exportVectorImage( sul, slr, sget, info ); 00812 } 00813 00814 template < class SrcIterator, class SrcAccessor > 00815 inline 00816 void exportImage( SrcIterator sul, SrcIterator slr, SrcAccessor sget, 00817 const ImageExportInfo & info, VigraTrueType ) 00818 { 00819 exportScalarImage( sul, slr, sget, info ); 00820 } 00821 00822 /********************************************************/ 00823 /* */ 00824 /* exportImage */ 00825 /* */ 00826 /********************************************************/ 00827 00828 /** \brief Write an image, given an \ref vigra::ImageExportInfo object. 00829 00830 <b> Declarations:</b> 00831 00832 pass arguments explicitly: 00833 \code 00834 namespace vigra { 00835 template <class SrcIterator, class SrcAccessor> 00836 void exportImage(SrcIterator sul, SrcIterator slr, SrcAccessor sget, 00837 ImageExportInfo const & info) 00838 } 00839 \endcode 00840 00841 00842 use argument objects in conjuction with \ref ArgumentObjectFactories: 00843 \code 00844 namespace vigra { 00845 template <class SrcIterator, class SrcAccessor> 00846 void exportImage(SrcIterator sul, SrcIterator slr, SrcAccessor sget, 00847 ImageExportInfo const & info) 00848 } 00849 \endcode 00850 00851 <b> Usage:</b> 00852 00853 <b>\#include</b> "<a href="impex_8hxx-source.html">vigra/impex.hxx</a>"<br> 00854 Namespace: vigra 00855 00856 \code 00857 00858 00859 vigra::BRGBImage out(w, h); 00860 ... 00861 00862 // write as JPEG image, using compression quality 80 00863 vigra::exportImage(srcImageRange(out), 00864 vigra::ImageExportInfo("myimage.jpg").setCompression("80")); 00865 00866 \endcode 00867 00868 <b> Preconditions:</b> 00869 00870 <UL> 00871 00872 <LI> the image file must be writable 00873 <LI> the file type must be one of 00874 00875 <DL> 00876 <DT>"BMP"<DD> Microsoft Windows bitmap image file. 00877 <DT>"GIF"<DD> CompuServe graphics interchange format; 8-bit color. 00878 <DT>"JPEG"<DD> Joint Photographic Experts Group JFIF format; compressed 24-bit color. (only available if libjpeg is installed) 00879 <DT>"PNG"<DD> Portable Network Graphic. (only available if libpng is installed) 00880 <DT>"PBM"<DD> Portable bitmap format (black and white). 00881 <DT>"PGM"<DD> Portable graymap format (gray scale). 00882 <DT>"PNM"<DD> Portable anymap. 00883 <DT>"PPM"<DD> Portable pixmap format (color). 00884 <DT>"SUN"<DD> SUN Rasterfile. 00885 <DT>"TIFF"<DD> Tagged Image File Format. (only available if libtiff is installed.) 00886 <DT>"VIFF"<DD> Khoros Visualization image file. 00887 </DL> 00888 00889 </UL> 00890 **/ 00891 template < class SrcIterator, class SrcAccessor > 00892 inline 00893 void exportImage( SrcIterator sul, SrcIterator slr, SrcAccessor sget, 00894 const ImageExportInfo & info ) 00895 { 00896 typedef typename NumericTraits<typename SrcAccessor::value_type>::isScalar is_scalar; 00897 exportImage( sul, slr, sget, info, is_scalar() ); 00898 } 00899 00900 template < class SrcIterator, class SrcAccessor > 00901 inline 00902 void exportImage( triple<SrcIterator, SrcIterator, SrcAccessor> src, 00903 const ImageExportInfo & info ) 00904 { 00905 exportImage( src.first, src.second, src.third, info ); 00906 } 00907 00908 //@} 00909 00910 } // namespace vigra 00911 00912 #endif /* VIGRA_IMPEX_HXX */
© Ullrich Köthe (koethe@informatik.uni-hamburg.de) |
html generated using doxygen and Python
|