IFileType.c
资源名称:ilib [点击查看]
上传用户:changbiao
上传日期:2007-01-13
资源大小:141k
文件大小:2k
源码类别:

图片显示

开发平台:

C/C++

  1. /*
  2.  * IFileType.c
  3.  *
  4.  * Image library
  5.  *
  6.  * Description:
  7.  * Portable routines to manipulate raster images.
  8.  *
  9.  * History:
  10.  * 01-Apr-00 Jim Winstead imw@trainedmonkey.com
  11.  * Added BMP.
  12.  * 19-Jul-99 Craig Knudsen cknudsen@radix.net
  13.  * Added PNG.
  14.  * 20-May-96 Craig Knudsen cknudsen@radix.net
  15.  * Created
  16.  *
  17.  ****************************************************************************/
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <ctype.h>
  21. #include <memory.h>
  22. #include "Ilib.h"
  23. #include "IlibP.h"
  24. IError IFileType ( file, format_return )
  25. char *file;
  26. IFileFormat *format_return;
  27. {
  28.   char *tmp, *ptr;
  29.   IError ret = INoError;
  30.   *format_return = IFORMAT_PPM; /* default */
  31.   tmp = (char *) malloc ( strlen ( file ) + 1 );
  32.   strcpy ( tmp, file );
  33.   for ( ptr = tmp; *ptr != ''; ptr++ )
  34.     *ptr = tolower ( *ptr );
  35.   /* find the last '.' */
  36.   for ( ptr = tmp + strlen ( tmp ) - 1; ( ptr != tmp ) && ( *ptr != '.' );
  37.     ptr-- ) ;
  38.   if ( *ptr == '.' ) {
  39.     ptr++;
  40.     if ( strcmp ( ptr, "gif" ) == 0 ) {
  41.       *format_return = IFORMAT_GIF;
  42. #ifndef HAVE_GIFLIB
  43.       ret = INoGIFSupport;
  44. #endif
  45.     } else if ( strcmp ( ptr, "ppm" ) == 0 )
  46.       *format_return = IFORMAT_PPM;
  47.     else if ( strcmp ( ptr, "pgm" ) == 0 )
  48.       *format_return = IFORMAT_PGM;
  49.     else if ( strcmp ( ptr, "pbm" ) == 0 )
  50.       *format_return = IFORMAT_PBM;
  51.     else if ( strcmp ( ptr, "xpm" ) == 0 )
  52.       *format_return = IFORMAT_XPM;
  53.     else if ( strcmp ( ptr, "xbm" ) == 0 )
  54.       *format_return = IFORMAT_XBM;
  55.     else if ( strcmp ( ptr, "png" ) == 0 )
  56.       *format_return = IFORMAT_PNG;
  57.     else if ( strcmp ( ptr, "jpeg" ) == 0 )
  58.       *format_return = IFORMAT_JPEG;
  59.     else if ( strcmp ( ptr, "jpg" ) == 0 )
  60.       *format_return = IFORMAT_JPEG;
  61.     else if ( strcmp ( ptr, "bmp" ) == 0 )
  62.       *format_return = IFORMAT_BMP;
  63.     else
  64.       ret = IInvalidFormat;
  65.   } else
  66.     ret = IInvalidFormat;
  67.   free ( tmp );
  68.   return ( ret );
  69. }