xp_comm_proj/build3d_2/build3d_2.c
/*----------------------------------------------------------------------
 * attempts to determine the format from the file itself
 */
attempts to determine the format from the file itself
attempts to determine the format from the file itself
static int FUNCget_image_format(const char *filename)
{
  FILE *fp;
  char *extension;
  unsigned char file_id[8];
  if ((fp = (FILE *) FILEfopen(filename, SIO_R_BIN)) == NULL)
    return(DV_IMAGE_FORMAT_NOFILE);
  if ((fread(file_id, 8, 1, fp)) != 1)
  {
    fclose(fp);
    return(DV_IMAGE_FORMAT_UNKNOWN);
  }
  fclose(fp);
  if (!strncmp((char *) file_id, "GIF87a", 6) || !strncmp((char *) file_id, "GIF89a", 6))
    return(DV_IMAGE_FORMAT_GIF);
  else if (file_id[0] == 0xff && file_id[1] == 0xd8 && file_id[2] == 0xff)
    return(DV_IMAGE_FORMAT_JPEG);
  else if (file_id[0] == 'P' && file_id[1] >= '1' && file_id[1] <= '6')
    return(DV_IMAGE_FORMAT_PBM);
  else if ((file_id[0] == 0x01 && file_id[1] == 0xda) || (file_id[0] == 0xda && file_id[1] == 0x01))
    return(DV_IMAGE_FORMAT_SGIRGB);
  else if (file_id[0] == 0x59 && (file_id[1] & 0x7f) == 0x26 && file_id[2] == 0x6a && (file_id[3] & 0x7f) == 0x15)
    return(DV_IMAGE_FORMAT_SUNRAS);
  else if ((file_id[0] == 'M' && file_id[1] == 'M') || (file_id[0] == 'I' && file_id[1] == 'I'))
    return(DV_IMAGE_FORMAT_TIFF);
  else if (file_id[0] == '%' && file_id[1] == '!')
    return(DV_IMAGE_FORMAT_PS);
  else if (file_id[0] == 'B' && file_id[1] == 'M')
    return(DV_IMAGE_FORMAT_BMP);
  else if (file_id[0] == 0x52 && file_id[1] == 0xcc)
    return(DV_IMAGE_FORMAT_UTAH);
  else if (file_id[0] == 0x1f && file_id[1] == 0x9d)
    return(DV_IMAGE_FORMAT_Z);
  else if (file_id[0] == 0x1f && file_id[1] == 0x8b)
    return(DV_IMAGE_FORMAT_GZIP);
  else if ((extension = strrchr(filename, '.')) && (!strcmp(&extension[1], "x") || !strcmp(&extension[1], "X")))
    return(DV_IMAGE_FORMAT_AVSX);
  else
    return(DV_IMAGE_FORMAT_UNKNOWN);
}
static int FUNCget_image_format ( const char * filename ) { FILE * fp ; char * extension ; unsigned char file_id [ 8 ] ; if ( ( fp = ( FILE * ) FILEfopen ( filename , SIO_R_BIN ) ) == NULL ) return ( DV_IMAGE_FORMAT_NOFILE ) ; if ( ( fread ( file_id , 8 , 1 , fp ) ) != 1 ) { fclose ( fp ) ; return ( DV_IMAGE_FORMAT_UNKNOWN ) ; } fclose ( fp ) ; if ( ! strncmp ( ( char * ) file_id , " " , 6 ) || ! strncmp ( ( char * ) file_id , " " , 6 ) ) return ( DV_IMAGE_FORMAT_GIF ) ; else if ( file_id [ 0 ] == 0xff && file_id [ 1 ] == 0xd8 && file_id [ 2 ] == 0xff ) return ( DV_IMAGE_FORMAT_JPEG ) ; else if ( file_id [ 0 ] == ' ' && file_id [ 1 ] >= ' ' && file_id [ 1 ] <= ' ' ) return ( DV_IMAGE_FORMAT_PBM ) ; else if ( ( file_id [ 0 ] == 0x01 && file_id [ 1 ] == 0xda ) || ( file_id [ 0 ] == 0xda && file_id [ 1 ] == 0x01 ) ) return ( DV_IMAGE_FORMAT_SGIRGB ) ; else if ( file_id [ 0 ] == 0x59 && ( file_id [ 1 ] & 0x7f ) == 0x26 && file_id [ 2 ] == 0x6a && ( file_id [ 3 ] & 0x7f ) == 0x15 ) return ( DV_IMAGE_FORMAT_SUNRAS ) ; else if ( ( file_id [ 0 ] == ' ' && file_id [ 1 ] == ' ' ) || ( file_id [ 0 ] == ' ' && file_id [ 1 ] == ' ' ) ) return ( DV_IMAGE_FORMAT_TIFF ) ; else if ( file_id [ 0 ] == ' ' && file_id [ 1 ] == ' ' ) return ( DV_IMAGE_FORMAT_PS ) ; else if ( file_id [ 0 ] == ' ' && file_id [ 1 ] == ' ' ) return ( DV_IMAGE_FORMAT_BMP ) ; else if ( file_id [ 0 ] == 0x52 && file_id [ 1 ] == 0xcc ) return ( DV_IMAGE_FORMAT_UTAH ) ; else if ( file_id [ 0 ] == 0x1f && file_id [ 1 ] == 0x9d ) return ( DV_IMAGE_FORMAT_Z ) ; else if ( file_id [ 0 ] == 0x1f && file_id [ 1 ] == 0x8b ) return ( DV_IMAGE_FORMAT_GZIP ) ; else if ( ( extension = strrchr ( filename , ' ' ) ) && ( ! strcmp ( & extension [ 1 ] , " " ) || ! strcmp ( & extension [ 1 ] , " " ) ) ) return ( DV_IMAGE_FORMAT_AVSX ) ; else return ( DV_IMAGE_FORMAT_UNKNOWN ) ; }
attempts to determine the format from the file itself
attempts to determine the format from the file itself
/* first open the file for existence check */ /* all others we try and id by their header info... */ /* not much we can do with < 8 bytes */ /* try to id from the file first, then if the filename has a .x/X extension
   * guess that it's an AVS .x file, else call it unknown
   */