xp_comm_proj/ReadGeoTiff/libtiff/tif_getimage.c
/*
 * Check the image to see if TIFFReadRGBAImage can deal with it.
 * 1/0 is returned according to whether or not the image can
 * be handled.  If 0 is returned, emsg contains the reason
 * why it is being rejected.
 */
Check the image to see if TIFFReadRGBAImage can deal with it.
1/0 is returned according to whether or not the image can
be handled.  If 0 is returned, emsg contains the reason
why it is being rejected.
Check the image to see if TIFFReadRGBAImage can deal with it . 1 / 0 is returned according to whether or not the image can be handled . If 0 is returned emsg contains the reason why it is being rejected .
int
TIFFRGBAImageOK(TIFF* tif, char emsg[1024])
{
    TIFFDirectory* td = &tif->tif_dir;
    uint16 photometric;
    int colorchannels;
    switch (td->td_bitspersample) {
    case 1: case 2: case 4:
    case 8: case 16:
	break;
    default:
	sprintf(emsg, "Sorry, can not handle images with %d-bit samples",
	    td->td_bitspersample);
	return (0);
    }
    colorchannels = td->td_samplesperpixel - td->td_extrasamples;
    if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometric)) {
	switch (colorchannels) {
	case 1:
	    photometric = PHOTOMETRIC_MINISBLACK;
	    break;
	case 3:
	    photometric = PHOTOMETRIC_RGB;
	    break;
	default:
	    sprintf(emsg, "Missing needed %s tag", photoTag);
	    return (0);
	}
    }
    switch (photometric) {
    case PHOTOMETRIC_MINISWHITE:
    case PHOTOMETRIC_MINISBLACK:
    case PHOTOMETRIC_PALETTE:
	if (td->td_planarconfig == PLANARCONFIG_CONTIG && td->td_samplesperpixel != 1) {
	    sprintf(emsg,
		"Sorry, can not handle contiguous data with %s=%d, and %s=%d",
		photoTag, photometric,
		"Samples/pixel", td->td_samplesperpixel);
	    return (0);
	}
	break;
    case PHOTOMETRIC_YCBCR:
	if (td->td_planarconfig != PLANARCONFIG_CONTIG) {
	    sprintf(emsg, "Sorry, can not handle YCbCr images with %s=%d",
		"Planarconfiguration", td->td_planarconfig);
	    return (0);
	}
	break;
    case PHOTOMETRIC_RGB: 
	if (colorchannels < 3) {
	    sprintf(emsg, "Sorry, can not handle RGB image with %s=%d",
		"Color channels", colorchannels);
	    return (0);
	}
	break;
#ifdef CMYK_SUPPORT
    case PHOTOMETRIC_SEPARATED:
	if (td->td_inkset != INKSET_CMYK) {
	    sprintf(emsg, "Sorry, can not handle separated image with %s=%d",
		"InkSet", td->td_inkset);
	    return (0);
	}
	if (td->td_samplesperpixel != 4) {
	    sprintf(emsg, "Sorry, can not handle separated image with %s=%d",
		"Samples/pixel", td->td_samplesperpixel);
	    return (0);
	}
	break;
#endif
    default:
	sprintf(emsg, "Sorry, can not handle image with %s=%d",
	    photoTag, photometric);
	return (0);
    }
    return (1);
}
int TIFFRGBAImageOK ( TIFF * tif , char emsg [ 1024 ] ) { TIFFDirectory * td = & tif -> tif_dir ; uint16 photometric ; int colorchannels ; switch ( td -> td_bitspersample ) { case 1 : case 2 : case 4 : case 8 : case 16 : break ; default : sprintf ( emsg , " " , td -> td_bitspersample ) ; return ( 0 ) ; } colorchannels = td -> td_samplesperpixel - td -> td_extrasamples ; if ( ! TIFFGetField ( tif , TIFFTAG_PHOTOMETRIC , & photometric ) ) { switch ( colorchannels ) { case 1 : photometric = PHOTOMETRIC_MINISBLACK ; break ; case 3 : photometric = PHOTOMETRIC_RGB ; break ; default : sprintf ( emsg , " " , photoTag ) ; return ( 0 ) ; } } switch ( photometric ) { case PHOTOMETRIC_MINISWHITE : case PHOTOMETRIC_MINISBLACK : case PHOTOMETRIC_PALETTE : if ( td -> td_planarconfig == PLANARCONFIG_CONTIG && td -> td_samplesperpixel != 1 ) { sprintf ( emsg , " " , photoTag , photometric , " " , td -> td_samplesperpixel ) ; return ( 0 ) ; } break ; case PHOTOMETRIC_YCBCR : if ( td -> td_planarconfig != PLANARCONFIG_CONTIG ) { sprintf ( emsg , " " , " " , td -> td_planarconfig ) ; return ( 0 ) ; } break ; case PHOTOMETRIC_RGB : if ( colorchannels < 3 ) { sprintf ( emsg , " " , " " , colorchannels ) ; return ( 0 ) ; } break ; #ifdef CMYK_SUPPORT case PHOTOMETRIC_SEPARATED : if ( td -> td_inkset != INKSET_CMYK ) { sprintf ( emsg , " " , " " , td -> td_inkset ) ; return ( 0 ) ; } if ( td -> td_samplesperpixel != 4 ) { sprintf ( emsg , " " , " " , td -> td_samplesperpixel ) ; return ( 0 ) ; } break ; #endif default : sprintf ( emsg , " " , photoTag , photometric ) ; return ( 0 ) ; } return ( 1 ) ; }
Check the image to see if TIFFReadRGBAImage can deal with it.
Check the image to see if TIFFReadRGBAImage can deal with it .