Ejemplo n.º 1
0
/*-----------------------------------------------------
        Parameters:

        Returns value:

        Description
------------------------------------------------------*/
IMAGE *
ImageRead(const char*fname)
{
  IMAGE   *I = NULL ;
  MATRIX  *mat ;
  FILE    *fp ;
  int     type, frame ;
  char    buf[STRLEN] ;

  strcpy(buf, fname) ;   /* don't destroy callers string */

  ImageUnpackFileName(buf, &frame, &type, buf) ;

  switch (type)
  {
  case TIFF_IMAGE:
    I = TiffReadImage(buf, frame) ;
    if (I == NULL)
      return(NULL) ;
    break ;
  case MATLAB_IMAGE:
    DiagPrintf(DIAG_WRITE,
               "ImageRead: buf=%s, frame=%d, type=%d (M=%d,H=%d)\n",
               buf, frame, type , MATLAB_IMAGE, HIPS_IMAGE);
    mat = MatlabRead(buf) ;
    if (!mat)
      ErrorReturn(NULL, (ERROR_NO_FILE, "ImageRead(%s) failed\n", buf)) ;
    I = ImageFromMatrix(mat, NULL) ;
    ImageInvert(I, I) ;
    MatrixFree(&mat) ;
    break ;
  case HIPS_IMAGE:
    fp = fopen(buf, "rb") ;
    if (!fp)
      ErrorReturn(NULL, (ERROR_NO_FILE, "ImageRead(%s, %d) failed\n",
                         buf, frame)) ;
    I = ImageFRead(fp, buf, frame, 1) ;
    fclose(fp) ;
    break ;
  case JPEG_IMAGE:
    I = JPEGReadImage(buf);
    break ;
  case PGM_IMAGE:
    I = PGMReadImage(buf);
    break;
  case PPM_IMAGE:
    I = PPMReadImage(buf);
    break;
  case PBM_IMAGE:
    I = PBMReadImage(buf);
    break;
  case RGBI_IMAGE:
    I= RGBReadImage(buf);
  default:
    break ;
  }
  return(I) ;
}
Ejemplo n.º 2
0
int Image32::ReadImage(char* fileName) {
    char* ext=GetFileExtension(fileName);
    int ret=0;
    if(!strcasecmp(ext,"bmp")) {
        ret=BMPReadImage(fileName,*this);
    }
    else if(!strcasecmp(ext,"jpg") || !strcasecmp(ext,"jpeg")) {
        ret=JPEGReadImage(fileName,*this);
    }
    else {};	// Unknown format
    delete[] ext;
    return ret;
}