00001 /************************************************************************************************** 00002 Software License Agreement (BSD License) 00003 00004 Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt 00005 All rights reserved. 00006 00007 Redistribution and use in source and binary forms, with or without modification, are permitted 00008 provided that the following conditions are met: 00009 00010 *Redistributions of source code must retain the above copyright notice, this list of 00011 conditions and the following disclaimer. 00012 *Redistributions in binary form must reproduce the above copyright notice, this list of 00013 conditions and the following disclaimer in the documentation and/or other materials provided 00014 with the distribution. 00015 *Neither the name of the University of Aveiro nor the names of its contributors may be used to 00016 endorse or promote products derived from this software without specific prior written permission. 00017 00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 00019 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 00020 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00021 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00024 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00025 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 ***************************************************************************************************/ 00032 //============================================================================= 00033 // Copyright � 2000 Point Grey Research, Inc. All Rights Reserved. 00034 // 00035 // This software is the confidential and proprietary information of Point 00036 // Grey Research, Inc. ("Confidential Information"). You shall not 00037 // disclose such Confidential Information and shall use it only in 00038 // accordance with the terms of the license agreement you entered into 00039 // with PGR. 00040 // 00041 // PGR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE 00042 // SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 00043 // IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 00044 // PURPOSE, OR NON-INFRINGEMENT. PGR SHALL NOT BE LIABLE FOR ANY DAMAGES 00045 // SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING 00046 // THIS SOFTWARE OR ITS DERIVATIVES. 00047 //============================================================================= 00048 //============================================================================= 00049 // $Id: pnmutils.h,v 1.14 2008/03/06 23:04:06 donm Exp $ 00050 //============================================================================= 00051 #ifndef _PNMUTILS_H_ 00052 #define _PNMUTILS_H_ 00053 00054 00055 //============================================================================= 00056 // 00057 // pnmutils: 00058 // 00059 // This file provides functions for reading and writing a PGM and PPM 00060 // files from and to a TriclopsImage. 00061 // Users are encouraged to modify this source to suit their own needs. 00062 //============================================================================= 00063 00064 00065 //============================================================================= 00066 // System Includes 00067 //============================================================================= 00068 #include <stdio.h> 00069 #include <stdlib.h> 00070 #include <string.h> 00071 00072 00073 //============================================================================= 00074 // PGR Includes 00075 //============================================================================= 00076 #include "triclops.h" 00077 00078 00079 #ifdef __cplusplus 00080 extern "C" 00081 { 00082 #endif 00083 00084 00085 //============================================================================= 00086 // pgmReadToTriclopsImage() 00087 // 00088 // This function reads an 8-bit pgm file into a TriclopsImage 00089 // structure. It allocates the data within the TriclopsImage to contain 00090 // the image data. This data must be freed after it is used by calling 00091 // 'freeImage()' 00092 // 00093 // return codes: 00094 // True - the file was successfully read and memory allocated 00095 // False - the file read failed (no memory was allocated) 00096 // 00097 TriclopsBool 00098 pgmReadToTriclopsImage( const char* filename, 00099 TriclopsImage* image ); 00100 00101 //============================================================================= 00102 // pgmReadToTriclopsImage16() 00103 // 00104 // This function reads an 16-bit pgm file into a TriclopsImage16 00105 // structure. It allocates the data within the TriclopsImage16 to 00106 // contain the image data. This data must be freed after it is used 00107 // by calling 'freeImage16()' 00108 // 00109 // return codes: 00110 // True - the file was successfully read and memory allocated 00111 // False - the file read failed (no memory was allocated) 00112 // 00113 TriclopsBool 00114 pgmReadToTriclopsImage16( const char* filename, 00115 TriclopsImage16* image ); 00116 00117 00118 //============================================================================= 00119 // 00120 // 00121 // 00122 // 00123 TriclopsBool 00124 pgmRead3ToTriclopsInput( const char* redFileName, 00125 const char* bluFileName, 00126 const char* greFileName, 00127 TriclopsInput* pInput ); 00128 00129 //============================================================================= 00130 // pgmReadToTriclopsInput() 00131 // 00132 // This function reads a pgm file into a TriclopsInput 00133 // structure (of type TriInp_RGB). 00134 // It allocates the data within the TriclopsInput to 00135 // contain the image data. This data must be freed after it is used 00136 // by calling 'freeInput()' 00137 // 00138 // This data is suitable to be be input into the Triclops stereo 00139 // library with a call to 'triclopsPreprocess()' 00140 // 00141 // NOTE: this uses a greyscale image and expects that the red/green 00142 // or red/green/blue channels be side by side or "row-interleaved". 00143 // 00144 // return codes: 00145 // True - the file was successfully read and memory allocated 00146 // False - the file read failed (no memory was allocated) 00147 // 00148 TriclopsBool 00149 pgmReadToTriclopsInput( const char* filename, 00150 TriclopsInput* input ); 00151 00152 00153 //============================================================================= 00154 // pgmReadToTriclopsInput() 00155 // 00156 // This function reads a pgm file into a TriclopsInput 00157 // structure (of type TriInp_RGB). 00158 // It allocates the data within the TriclopsInput to 00159 // contain the image data. This data must be freed after it is used 00160 // by calling 'freeInput()' 00161 // 00162 // This data is suitable to be be input into the Triclops stereo 00163 // library with a call to 'triclopsPreprocess()' 00164 // 00165 // NOTE: this uses a greyscale image and expects that the red/green 00166 // or red/green/blue channels be side by side or "row-interleaved". 00167 // 00168 // return codes: 00169 // True - the file was successfully read and memory allocated 00170 // False - the file read failed (no memory was allocated) 00171 // 00172 TriclopsBool 00173 pgmReadToTriclopsInput( const char* filename, 00174 TriclopsInput* input ); 00175 00176 00177 //============================================================================= 00178 // ppmReadToTriclopsInput() 00179 // 00180 // This function reads a ppm file into a TriclopsInput 00181 // structure (of type TriInp_RGB_32BITPACKED). 00182 // It allocates the data within the TriclopsInput to 00183 // contain the image data. This data must be freed after it is used 00184 // by calling 'freeInput()' 00185 // 00186 // This data is suitable to be be input into the Triclops stereo 00187 // library with a call to 'triclopsPreprocess()' 00188 // 00189 // return codes: 00190 // True - the file was successfully read and memory allocated 00191 // False - the file read failed (no memory was allocated) 00192 // 00193 TriclopsBool 00194 ppmReadToTriclopsInput( const char* filename, 00195 TriclopsInput* input ); 00196 00197 00198 //============================================================================= 00199 // ppmReadToTriclopsInputRGB() 00200 // 00201 // This function reads a ppm file into a TriclopsInput 00202 // structure (of type TriInp_RGB). 00203 // It allocates the data within the TriclopsInput to 00204 // contain the image data. This data must be freed after it is used 00205 // by calling 'freeInput()' 00206 // 00207 // This data is suitable to be be input into the Triclops stereo 00208 // library with a call to 'triclopsPreprocess()' 00209 // 00210 // return codes: 00211 // True - the file was successfully read and memory allocated 00212 // False - the file read failed (no memory was allocated) 00213 // 00214 TriclopsBool 00215 ppmReadToTriclopsInputRGB( const char* filename, 00216 TriclopsInput* input ); 00217 00218 00219 //============================================================================= 00220 // freeInput() 00221 // 00222 // This function frees the image memory associated with a TriclopsInput. 00223 // This needs to be called after the user is finished with a 00224 // TriclopsInput structure that was created from a called to 00225 // 'ppmReadToTriclopsInput()' 00226 // 00227 // return codes: 00228 // True - the memory was freed 00229 // 00230 TriclopsBool 00231 freeInput( TriclopsInput* input ); 00232 00233 00234 //============================================================================= 00235 // freeImage() 00236 // 00237 // This function frees the image memory associated with a TriclopsImage. 00238 // This needs to be called after the user is finished with a 00239 // TriclopsImage structure that was created from a called to 00240 // 'pgmReadToTriclopsImage()' 00241 // 00242 // return codes: 00243 // True - the memory was freed 00244 // 00245 TriclopsBool 00246 freeImage( TriclopsImage* pimage ); 00247 00248 00249 //============================================================================= 00250 // freeImage16() 00251 // 00252 // This function frees the image memory associated with a 00253 // TriclopsImage16. 00254 // This needs to be called after the user is finished with a 00255 // TriclopsImage structure that was created from a called to 00256 // 'pgmReadToTriclopsImage16()' 00257 // 00258 // return codes: 00259 // True - the memory was freed 00260 // 00261 TriclopsBool 00262 freeImage16( TriclopsImage16* pimage ); 00263 00264 00265 //============================================================================= 00266 // pgmWriteFromTriclopsImage() 00267 // 00268 // This function writes an 8-bit pgm file from a TriclopsImage 00269 // structure. 00270 // 00271 // return codes: 00272 // True - the file was successfully written 00273 // False - 'filename' could not be opened for writing 00274 // 00275 TriclopsBool 00276 pgmWriteFromTriclopsImage( const char* filename, 00277 TriclopsImage* image ); 00278 00279 00280 //============================================================================= 00281 // ppmWriteFromTriclopsColorImage() 00282 // 00283 // This function writes an 24-bit ppm file from a TriclopsColorImage 00284 // structure. 00285 // 00286 // return codes: 00287 // True - the file was successfully written 00288 // False - 'filename' could not be opened for writing 00289 // 00290 TriclopsBool 00291 ppmWriteFromTriclopsColorImage( const char* filename, 00292 TriclopsColorImage* image ); 00293 00294 00295 //============================================================================= 00296 // pgmWrite3FromTriclopsInput() 00297 // 00298 // This function writes 3 8-bit pgm files from a TriclopsInput structure. 00299 // These correspond to the appropriate channels of the image. 00300 // 00301 // return codes: 00302 // True - the file was successfully written 00303 // False - 'filename' could not be opened for writing 00304 // 00305 TriclopsBool 00306 pgmWrite3FromTriclopsInput( const char* redFilename, 00307 const char* greFilename, 00308 const char* bluFilename, 00309 TriclopsInput* input ); 00310 00311 00312 //============================================================================= 00313 // pgmWrite3FromTriclopsInputWithComment() 00314 // 00315 // This function writes 3 8-bit pgm files from a TriclopsInput structure. 00316 // These correspond to the appropriate channels of the image. The comment 00317 // will be stored in each file (pass in NULL if no comment is desired). 00318 // 00319 // return codes: 00320 // True - the file was successfully written 00321 // False - 'filename' could not be opened for writing 00322 // 00323 TriclopsBool 00324 pgmWrite3FromTriclopsInputWithComment( const char* redFilename, 00325 const char* greFilename, 00326 const char* bluFilename, 00327 const char* comment, 00328 TriclopsInput* input ); 00329 00330 00331 //============================================================================= 00332 // pgmWriteFromTriclopsImage16() 00333 // 00334 // This function writes an 16-bit pgm file from a TriclopsImage 00335 // structure. 00336 // 00337 // return codes: 00338 // True - the file was successfully written 00339 // False - 'filename' could not be opened for writing 00340 // 00341 TriclopsBool 00342 pgmWriteFromTriclopsImage16( const char* filename, 00343 TriclopsImage16* image ); 00344 00345 00346 //============================================================================= 00347 // ppmWriteFromTriclopsInput() 00348 // 00349 // This function writes an 24-bit ppm file from a TriclopsInput 00350 // structure. 00351 // 00352 // return codes: 00353 // True - the file was successfully written 00354 // False - 'filename' could not be opened for writing 00355 // - or the TriclopsInput was not in a supported format 00356 // 00357 TriclopsBool 00358 ppmWriteFromTriclopsInput( const char* filename, 00359 TriclopsInput* input ); 00360 00361 00362 //============================================================================= 00363 // 00364 // 00365 // 00366 // 00367 TriclopsBool 00368 ppmWriteFromTriclopsInputWithComment( const char* filename, 00369 const char* comment, 00370 TriclopsInput* input ); 00371 00372 //============================================================================= 00373 // pgmWriteFromTriclopsInput() 00374 // 00375 // This function writes an 24-bit ppm file from a TriclopsInput 00376 // structure. 00377 // 00378 // nCameras - if it is known that the Input has only 2 cameras, 00379 // this can be changed to a value of 2. Otherwise it should 00380 // be 3 00381 // 00382 // return codes: 00383 // True - the file was successfully written 00384 // False - 'filename' could not be opened for writing 00385 // - or the TriclopsInput was not in a supported format 00386 // 00387 TriclopsBool 00388 pgmWriteFromTriclopsInput( const char* filename, 00389 TriclopsInput* input, 00390 int nCameras ); 00391 00392 00393 //============================================================================= 00394 // 00395 // 00396 // 00397 // 00398 TriclopsBool 00399 pgmWriteFromTriclopsInputWithComment( const char* filename, 00400 const char* comment, 00401 TriclopsInput* input, 00402 int nCameras = 3 ); 00403 00404 00405 00406 //============================================================================= 00407 // pgmWriteFromTriclopsInput() 00408 // 00409 // This function writes an 8-bit pgm file from a TriclopsInput 00410 // structure. 00411 // 00412 // nCameras - if it is known that the Input has only 2 cameras, 00413 // this can be changed to a value of 2. Otherwise it should 00414 // be 3. 00415 // 00416 // return codes: 00417 // True - the file was successfully written 00418 // False - 'filename' could not be opened for writing 00419 // - or the TriclopsInput was not in a supported format 00420 // 00421 TriclopsBool 00422 pgmWriteFromTriclopsInput( const char* filename, 00423 TriclopsInput* input, 00424 int nCameras ); 00425 00426 00427 //============================================================================= 00428 // pgmWriteFromTriclopsInputWithComment() 00429 // 00430 // This function writes an 8-bit pgm file from a TriclopsInput 00431 // structure. The comment may be NULL. 00432 // 00433 // nCameras - if it is known that the Input has only 2 cameras, 00434 // this can be changed to a value of 2. Otherwise it should 00435 // be 3. 00436 // 00437 // return codes: 00438 // True - the file was successfully written 00439 // False - 'filename' could not be opened for writing 00440 // - or the TriclopsInput was not in a supported format 00441 // 00442 TriclopsBool 00443 pgmWriteFromTriclopsInputWithComment( const char* filename, 00444 const char* comment, 00445 TriclopsInput* input, 00446 int nCameras ); 00447 00448 00449 #ifdef __cplusplus 00450 } 00451 #endif 00452 00453 00454 #endif //#ifndef _PNMUTILS_H_