stuff
This commit is contained in:
parent
96f1af3f60
commit
dafd0030f0
@ -37,7 +37,6 @@ libconversion_la_SOURCES = \
|
||||
im_system.c \
|
||||
im_print.c \
|
||||
im_tbjoin.c \
|
||||
im_tile_cache.c \
|
||||
im_text.c \
|
||||
im_thresh.c \
|
||||
im_vips2mask.c \
|
||||
|
@ -1444,355 +1444,6 @@ static im_function zoom_desc = {
|
||||
zoom_args /* Arg list */
|
||||
};
|
||||
|
||||
static int
|
||||
jpeg2vips_vec( im_object *argv )
|
||||
{
|
||||
char *in = argv[0];
|
||||
IMAGE *out = argv[1];
|
||||
|
||||
if( im_jpeg2vips( in, out ) )
|
||||
return( -1 );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static im_arg_desc jpeg2vips_args[] = {
|
||||
IM_INPUT_STRING( "in" ),
|
||||
IM_OUTPUT_IMAGE( "out" )
|
||||
};
|
||||
|
||||
static im_function jpeg2vips_desc = {
|
||||
"im_jpeg2vips", /* Name */
|
||||
"convert from jpeg", /* Description */
|
||||
0, /* Flags */
|
||||
jpeg2vips_vec, /* Dispatch function */
|
||||
IM_NUMBER( jpeg2vips_args ), /* Size of arg list */
|
||||
jpeg2vips_args /* Arg list */
|
||||
};
|
||||
|
||||
static int
|
||||
vips2jpeg_vec( im_object *argv )
|
||||
{
|
||||
IMAGE *in = argv[0];
|
||||
char *out = argv[1];
|
||||
|
||||
if( im_vips2jpeg( in, out ) )
|
||||
return( -1 );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static im_arg_desc vips2jpeg_args[] = {
|
||||
IM_INPUT_IMAGE( "in" ),
|
||||
IM_INPUT_STRING( "out" )
|
||||
};
|
||||
|
||||
static im_function vips2jpeg_desc = {
|
||||
"im_vips2jpeg", /* Name */
|
||||
"convert to jpeg", /* Description */
|
||||
0, /* Flags */
|
||||
vips2jpeg_vec, /* Dispatch function */
|
||||
IM_NUMBER( vips2jpeg_args ), /* Size of arg list */
|
||||
vips2jpeg_args /* Arg list */
|
||||
};
|
||||
|
||||
static int
|
||||
vips2mimejpeg_vec( im_object *argv )
|
||||
{
|
||||
IMAGE *in = argv[0];
|
||||
int qfac = *((int *) argv[1]);
|
||||
|
||||
if( im_vips2mimejpeg( in, qfac ) )
|
||||
return( -1 );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static im_arg_desc vips2mimejpeg_args[] = {
|
||||
IM_INPUT_IMAGE( "in" ),
|
||||
IM_INPUT_INT( "qfac" )
|
||||
};
|
||||
|
||||
static im_function vips2mimejpeg_desc = {
|
||||
"im_vips2mimejpeg", /* Name */
|
||||
"convert to jpeg as mime type on stdout", /* Description */
|
||||
0, /* Flags */
|
||||
vips2mimejpeg_vec, /* Dispatch function */
|
||||
IM_NUMBER( vips2mimejpeg_args ), /* Size of arg list */
|
||||
vips2mimejpeg_args /* Arg list */
|
||||
};
|
||||
|
||||
/* Args for vips2png.
|
||||
*/
|
||||
static im_arg_desc vips2png_args[] = {
|
||||
IM_INPUT_IMAGE( "in" ),
|
||||
IM_INPUT_STRING( "out" )
|
||||
};
|
||||
|
||||
/* Call im_vips2png via arg vector.
|
||||
*/
|
||||
static int
|
||||
vips2png_vec( im_object *argv )
|
||||
{
|
||||
return( im_vips2png( argv[0], argv[1] ) );
|
||||
}
|
||||
|
||||
/* Description of im_vips2png.
|
||||
*/
|
||||
static im_function vips2png_desc = {
|
||||
"im_vips2png", /* Name */
|
||||
"convert VIPS image to PNG file", /* Description */
|
||||
0,
|
||||
vips2png_vec, /* Dispatch function */
|
||||
IM_NUMBER( vips2png_args ), /* Size of arg list */
|
||||
vips2png_args /* Arg list */
|
||||
};
|
||||
|
||||
/* Args for png2vips.
|
||||
*/
|
||||
static im_arg_desc png2vips_args[] = {
|
||||
IM_INPUT_STRING( "in" ),
|
||||
IM_OUTPUT_IMAGE( "out" )
|
||||
};
|
||||
|
||||
/* Call im_png2vips via arg vector.
|
||||
*/
|
||||
static int
|
||||
png2vips_vec( im_object *argv )
|
||||
{
|
||||
return( im_png2vips( argv[0], argv[1] ) );
|
||||
}
|
||||
|
||||
/* Description of im_png2vips.
|
||||
*/
|
||||
static im_function png2vips_desc = {
|
||||
"im_png2vips", /* Name */
|
||||
"convert PNG file to VIPS image", /* Description */
|
||||
0,
|
||||
png2vips_vec, /* Dispatch function */
|
||||
IM_NUMBER( png2vips_args ), /* Size of arg list */
|
||||
png2vips_args /* Arg list */
|
||||
};
|
||||
|
||||
/* Args for exr2vips.
|
||||
*/
|
||||
static im_arg_desc exr2vips_args[] = {
|
||||
IM_INPUT_STRING( "in" ),
|
||||
IM_OUTPUT_IMAGE( "out" )
|
||||
};
|
||||
|
||||
/* Call im_exr2vips via arg vector.
|
||||
*/
|
||||
static int
|
||||
exr2vips_vec( im_object *argv )
|
||||
{
|
||||
return( im_exr2vips( argv[0], argv[1] ) );
|
||||
}
|
||||
|
||||
/* Description of im_exr2vips.
|
||||
*/
|
||||
static im_function exr2vips_desc = {
|
||||
"im_exr2vips", /* Name */
|
||||
"convert an OpenEXR file to VIPS", /* Description */
|
||||
0,
|
||||
exr2vips_vec, /* Dispatch function */
|
||||
IM_NUMBER( exr2vips_args ), /* Size of arg list */
|
||||
exr2vips_args /* Arg list */
|
||||
};
|
||||
|
||||
/* Args for vips2tiff.
|
||||
*/
|
||||
static im_arg_desc vips2tiff_args[] = {
|
||||
IM_INPUT_IMAGE( "in" ),
|
||||
IM_INPUT_STRING( "out" )
|
||||
};
|
||||
|
||||
/* Call im_vips2tiff via arg vector.
|
||||
*/
|
||||
static int
|
||||
vips2tiff_vec( im_object *argv )
|
||||
{
|
||||
return( im_vips2tiff( argv[0], argv[1] ) );
|
||||
}
|
||||
|
||||
/* Description of im_vips2tiff.
|
||||
*/
|
||||
static im_function vips2tiff_desc = {
|
||||
"im_vips2tiff", /* Name */
|
||||
"convert VIPS image to TIFF file", /* Description */
|
||||
0,
|
||||
vips2tiff_vec, /* Dispatch function */
|
||||
IM_NUMBER( vips2tiff_args ), /* Size of arg list */
|
||||
vips2tiff_args /* Arg list */
|
||||
};
|
||||
|
||||
/* Args for magick2vips.
|
||||
*/
|
||||
static im_arg_desc magick2vips_args[] = {
|
||||
IM_INPUT_STRING( "in" ),
|
||||
IM_OUTPUT_IMAGE( "out" )
|
||||
};
|
||||
|
||||
/* Call im_magick2vips via arg vector.
|
||||
*/
|
||||
static int
|
||||
magick2vips_vec( im_object *argv )
|
||||
{
|
||||
return( im_magick2vips( argv[0], argv[1] ) );
|
||||
}
|
||||
|
||||
/* Description of im_magick2vips.
|
||||
*/
|
||||
static im_function magick2vips_desc = {
|
||||
"im_magick2vips", /* Name */
|
||||
"load file with libMagick", /* Description */
|
||||
0,
|
||||
magick2vips_vec, /* Dispatch function */
|
||||
IM_NUMBER( magick2vips_args ), /* Size of arg list */
|
||||
magick2vips_args /* Arg list */
|
||||
};
|
||||
|
||||
/* Args for tiff2vips.
|
||||
*/
|
||||
static im_arg_desc tiff2vips_args[] = {
|
||||
IM_INPUT_STRING( "in" ),
|
||||
IM_OUTPUT_IMAGE( "out" )
|
||||
};
|
||||
|
||||
/* Call im_tiff2vips via arg vector.
|
||||
*/
|
||||
static int
|
||||
tiff2vips_vec( im_object *argv )
|
||||
{
|
||||
return( im_tiff2vips( argv[0], argv[1] ) );
|
||||
}
|
||||
|
||||
/* Description of im_tiff2vips.
|
||||
*/
|
||||
static im_function tiff2vips_desc = {
|
||||
"im_tiff2vips", /* Name */
|
||||
"convert TIFF file to VIPS image", /* Description */
|
||||
0,
|
||||
tiff2vips_vec, /* Dispatch function */
|
||||
IM_NUMBER( tiff2vips_args ), /* Size of arg list */
|
||||
tiff2vips_args /* Arg list */
|
||||
};
|
||||
|
||||
static int
|
||||
analyze2vips_vec( im_object *argv )
|
||||
{
|
||||
const char *in = argv[0];
|
||||
IMAGE *out = argv[1];
|
||||
|
||||
return( im_analyze2vips( in, out ) );
|
||||
}
|
||||
|
||||
static im_arg_desc analyze2vips_arg_types[] = {
|
||||
IM_INPUT_STRING( "filename" ),
|
||||
IM_OUTPUT_IMAGE( "im" )
|
||||
};
|
||||
|
||||
static im_function analyze2vips_desc = {
|
||||
"im_analyze2vips", /* Name */
|
||||
"read a file in analyze format",/* Description */
|
||||
0, /* Flags */
|
||||
analyze2vips_vec, /* Dispatch function */
|
||||
IM_NUMBER( analyze2vips_arg_types ),/* Size of arg list */
|
||||
analyze2vips_arg_types /* Arg list */
|
||||
};
|
||||
|
||||
static int
|
||||
csv2vips_vec( im_object *argv )
|
||||
{
|
||||
const char *in = argv[0];
|
||||
IMAGE *out = argv[1];
|
||||
|
||||
return( im_csv2vips( in, out ) );
|
||||
}
|
||||
|
||||
static im_arg_desc csv2vips_arg_types[] = {
|
||||
IM_INPUT_STRING( "filename" ),
|
||||
IM_OUTPUT_IMAGE( "im" )
|
||||
};
|
||||
|
||||
static im_function csv2vips_desc = {
|
||||
"im_csv2vips", /* Name */
|
||||
"read a file in csv format",/* Description */
|
||||
0, /* Flags */
|
||||
csv2vips_vec, /* Dispatch function */
|
||||
IM_NUMBER( csv2vips_arg_types ),/* Size of arg list */
|
||||
csv2vips_arg_types /* Arg list */
|
||||
};
|
||||
|
||||
static int
|
||||
vips2csv_vec( im_object *argv )
|
||||
{
|
||||
IMAGE *in = argv[0];
|
||||
const char *filename = argv[1];
|
||||
|
||||
return( im_vips2csv( in, filename ) );
|
||||
}
|
||||
|
||||
static im_arg_desc vips2csv_arg_types[] = {
|
||||
IM_INPUT_IMAGE( "in" ),
|
||||
IM_INPUT_STRING( "filename" )
|
||||
};
|
||||
|
||||
static im_function vips2csv_desc = {
|
||||
"im_vips2csv", /* Name */
|
||||
"write an image in csv format", /* Description */
|
||||
0, /* Flags */
|
||||
vips2csv_vec, /* Dispatch function */
|
||||
IM_NUMBER( vips2csv_arg_types ),/* Size of arg list */
|
||||
vips2csv_arg_types /* Arg list */
|
||||
};
|
||||
|
||||
static int
|
||||
ppm2vips_vec( im_object *argv )
|
||||
{
|
||||
const char *in = argv[0];
|
||||
IMAGE *out = argv[1];
|
||||
|
||||
return( im_ppm2vips( in, out ) );
|
||||
}
|
||||
|
||||
static im_arg_desc ppm2vips_arg_types[] = {
|
||||
IM_INPUT_STRING( "filename" ),
|
||||
IM_OUTPUT_IMAGE( "im" )
|
||||
};
|
||||
|
||||
static im_function ppm2vips_desc = {
|
||||
"im_ppm2vips", /* Name */
|
||||
"read a file in pbm/pgm/ppm format", /* Description */
|
||||
0, /* Flags */
|
||||
ppm2vips_vec, /* Dispatch function */
|
||||
IM_NUMBER( ppm2vips_arg_types ),/* Size of arg list */
|
||||
ppm2vips_arg_types /* Arg list */
|
||||
};
|
||||
|
||||
static int
|
||||
vips2ppm_vec( im_object *argv )
|
||||
{
|
||||
IMAGE *im = argv[0];
|
||||
const char *filename = argv[1];
|
||||
|
||||
return( im_vips2ppm( im, filename ) );
|
||||
}
|
||||
|
||||
static im_arg_desc vips2ppm_arg_types[] = {
|
||||
IM_INPUT_IMAGE( "im" ),
|
||||
IM_INPUT_STRING( "filename" )
|
||||
};
|
||||
|
||||
static im_function vips2ppm_desc = {
|
||||
"im_vips2ppm", /* Name */
|
||||
"write a file in pbm/pgm/ppm format", /* Description */
|
||||
0, /* Flags */
|
||||
vips2ppm_vec, /* Dispatch function */
|
||||
IM_NUMBER( vips2ppm_arg_types ),/* Size of arg list */
|
||||
vips2ppm_arg_types /* Arg list */
|
||||
};
|
||||
|
||||
/* Call im_msb via arg vector.
|
||||
*/
|
||||
static int
|
||||
@ -1934,7 +1585,6 @@ static im_function *conv_list[] = {
|
||||
©_swap_desc,
|
||||
©_set_desc,
|
||||
©_set_meta_desc,
|
||||
&csv2vips_desc,
|
||||
&extract_area_desc,
|
||||
&extract_areabands_desc,
|
||||
&extract_band_desc,
|
||||
@ -1947,16 +1597,10 @@ static im_function *conv_list[] = {
|
||||
&grid_desc,
|
||||
&insert_desc,
|
||||
&insert_noexpand_desc,
|
||||
&jpeg2vips_desc,
|
||||
&lrjoin_desc,
|
||||
&magick2vips_desc,
|
||||
&mask2vips_desc,
|
||||
&msb_desc,
|
||||
&msb_band_desc,
|
||||
&png2vips_desc,
|
||||
&exr2vips_desc,
|
||||
&ppm2vips_desc,
|
||||
&analyze2vips_desc,
|
||||
&print_desc,
|
||||
&recomb_desc,
|
||||
&replicate_desc,
|
||||
@ -1973,14 +1617,7 @@ static im_function *conv_list[] = {
|
||||
&tbjoin_desc,
|
||||
&text_desc,
|
||||
&thresh_desc,
|
||||
&tiff2vips_desc,
|
||||
&vips2csv_desc,
|
||||
&vips2jpeg_desc,
|
||||
&vips2mask_desc,
|
||||
&vips2mimejpeg_desc,
|
||||
&vips2png_desc,
|
||||
&vips2ppm_desc,
|
||||
&vips2tiff_desc,
|
||||
&wrap_desc,
|
||||
&zoom_desc
|
||||
};
|
||||
|
@ -1,61 +1,22 @@
|
||||
noinst_LTLIBRARIES = libconversion.la
|
||||
noinst_LTLIBRARIES = libformat.la
|
||||
|
||||
libconversion_la_SOURCES = \
|
||||
im_bernd.c \
|
||||
im_vips2tiff.c \
|
||||
im_tiff2vips.c \
|
||||
conver_dispatch.c \
|
||||
libformat_la_SOURCES = \
|
||||
dbh.h \
|
||||
im_bandjoin.c \
|
||||
format_dispatch.c \
|
||||
im_analyze2vips.c \
|
||||
im_black.c \
|
||||
im_c2amph.c \
|
||||
im_c2rect.c \
|
||||
im_c2imag.c \
|
||||
im_c2ps.c \
|
||||
im_c2real.c \
|
||||
im_clip.c \
|
||||
im_copy.c \
|
||||
im_csv2vips.c \
|
||||
im_vips2csv.c \
|
||||
im_extract.c \
|
||||
im_exr2vips.c \
|
||||
im_falsecolour.c \
|
||||
im_fliphor.c \
|
||||
im_flipver.c \
|
||||
im_gbandjoin.c \
|
||||
im_insert.c \
|
||||
im_jpeg2vips.c \
|
||||
im_lrjoin.c \
|
||||
im_magick2vips.c \
|
||||
im_mask2vips.c \
|
||||
im_msb.c \
|
||||
im_png2vips.c \
|
||||
im_ppm2vips.c \
|
||||
im_recomb.c \
|
||||
im_replicate.c \
|
||||
im_grid.c \
|
||||
im_raw2vips.c \
|
||||
im_ri2c.c \
|
||||
im_rightshift_size.c \
|
||||
im_rot180.c \
|
||||
im_rot270.c \
|
||||
im_rot90.c \
|
||||
im_scale.c \
|
||||
im_scaleps.c \
|
||||
im_slice.c \
|
||||
im_subsample.c \
|
||||
im_system.c \
|
||||
im_print.c \
|
||||
im_tbjoin.c \
|
||||
im_tiff2vips.c \
|
||||
im_tile_cache.c \
|
||||
im_text.c \
|
||||
im_thresh.c \
|
||||
im_vips2mask.c \
|
||||
im_vips2csv.c \
|
||||
im_vips2jpeg.c \
|
||||
im_vips2ppm.c \
|
||||
im_vips2png.c \
|
||||
im_wrap.c \
|
||||
im_zoom.c
|
||||
im_vips2ppm.c \
|
||||
im_vips2tiff.c
|
||||
|
||||
INCLUDES = -I${top_srcdir}/include @VIPS_CFLAGS@ @VIPS_INCLUDES@
|
||||
|
File diff suppressed because it is too large
Load Diff
530
libsrc/format/predicate.c
Normal file
530
libsrc/format/predicate.c
Normal file
@ -0,0 +1,530 @@
|
||||
/* Test various predicates.
|
||||
*
|
||||
* J.Cupitt, 8/4/93.
|
||||
* 13/10/95 JC
|
||||
* - ANSIfied
|
||||
* - im_ispoweroftwo() added
|
||||
* 14/11/96 Jc
|
||||
* - im_isjpeg() added
|
||||
* 25/3/97 JC
|
||||
* - im_isvips() added
|
||||
* 14/4/97 JC
|
||||
* - im_istifftiled() added
|
||||
* 29/10/98 JC
|
||||
* - im_isMSBfirst() and im_amiMSBfirst() added
|
||||
* 16/6/99 JC
|
||||
* - added im_existsf()
|
||||
* 22/11/00 JC
|
||||
* - added im_isppm()
|
||||
* 23/4/01 JC
|
||||
* - HAVE_TIFF turns on TIFFness
|
||||
* 19/10/02 HB
|
||||
* - PNG added
|
||||
* 1/5/06
|
||||
* - added exr
|
||||
* 3/8/07
|
||||
* - cleanups
|
||||
* 22/5/08
|
||||
* - now just formats
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
This file is part of VIPS.
|
||||
|
||||
VIPS is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
|
||||
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
#include <vips/intl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif /*HAVE_UNISTD_H*/
|
||||
#ifdef HAVE_IO_H
|
||||
#include <io.h>
|
||||
#endif /*HAVE_IO_H*/
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <vips/vips.h>
|
||||
|
||||
#ifdef HAVE_TIFF
|
||||
#include <tiffio.h>
|
||||
#endif /*HAVE_TIFF*/
|
||||
|
||||
#ifdef HAVE_PNG
|
||||
#include <png.h>
|
||||
#endif /*HAVE_PNG*/
|
||||
|
||||
#ifdef WITH_DMALLOC
|
||||
#include <dmalloc.h>
|
||||
#endif /*WITH_DMALLOC*/
|
||||
|
||||
/* Test BandFmt.
|
||||
*/
|
||||
int
|
||||
im_isint( IMAGE *im )
|
||||
{
|
||||
switch( im->BandFmt ) {
|
||||
case IM_BANDFMT_UCHAR:
|
||||
case IM_BANDFMT_CHAR:
|
||||
case IM_BANDFMT_USHORT:
|
||||
case IM_BANDFMT_SHORT:
|
||||
case IM_BANDFMT_UINT:
|
||||
case IM_BANDFMT_INT:
|
||||
return( 1 );
|
||||
|
||||
case IM_BANDFMT_FLOAT:
|
||||
case IM_BANDFMT_DOUBLE:
|
||||
case IM_BANDFMT_COMPLEX:
|
||||
case IM_BANDFMT_DPCOMPLEX:
|
||||
return( 0 );
|
||||
|
||||
default:
|
||||
error_exit( "im_isint: unknown image BandFmt" );
|
||||
/*NOTREACHED*/
|
||||
return( -1 );
|
||||
}
|
||||
}
|
||||
|
||||
/* Test endianness of an image. SPARC is MSB first
|
||||
*/
|
||||
int
|
||||
im_isMSBfirst( IMAGE *im )
|
||||
{
|
||||
if( im->magic == IM_MAGIC_SPARC )
|
||||
return( 1 );
|
||||
else
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/* Test this processor for endianness. True for SPARC order.
|
||||
*/
|
||||
int
|
||||
im_amiMSBfirst( void )
|
||||
{
|
||||
int test;
|
||||
unsigned char *p = (unsigned char *) &test;
|
||||
|
||||
test = 0;
|
||||
p[0] = 255;
|
||||
|
||||
if( test == 255 )
|
||||
return( 0 );
|
||||
else
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
int
|
||||
im_isuint( IMAGE *im )
|
||||
{
|
||||
switch( im->BandFmt ) {
|
||||
case IM_BANDFMT_UCHAR:
|
||||
case IM_BANDFMT_USHORT:
|
||||
case IM_BANDFMT_UINT:
|
||||
return( 1 );
|
||||
|
||||
case IM_BANDFMT_INT:
|
||||
case IM_BANDFMT_SHORT:
|
||||
case IM_BANDFMT_CHAR:
|
||||
case IM_BANDFMT_FLOAT:
|
||||
case IM_BANDFMT_DOUBLE:
|
||||
case IM_BANDFMT_COMPLEX:
|
||||
case IM_BANDFMT_DPCOMPLEX:
|
||||
return( 0 );
|
||||
|
||||
default:
|
||||
error_exit( "im_isuint: unknown image BandFmt" );
|
||||
/*NOTREACHED*/
|
||||
return( -1 );
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
im_isfloat( IMAGE *im )
|
||||
{
|
||||
switch( im->BandFmt ) {
|
||||
case IM_BANDFMT_FLOAT:
|
||||
case IM_BANDFMT_DOUBLE:
|
||||
return( 1 );
|
||||
|
||||
case IM_BANDFMT_UCHAR:
|
||||
case IM_BANDFMT_CHAR:
|
||||
case IM_BANDFMT_USHORT:
|
||||
case IM_BANDFMT_SHORT:
|
||||
case IM_BANDFMT_UINT:
|
||||
case IM_BANDFMT_INT:
|
||||
case IM_BANDFMT_COMPLEX:
|
||||
case IM_BANDFMT_DPCOMPLEX:
|
||||
return( 0 );
|
||||
|
||||
default:
|
||||
error_exit( "im_isfloat: unknown image BandFmt" );
|
||||
/*NOTREACHED*/
|
||||
return( -1 );
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
im_isscalar( IMAGE *im )
|
||||
{
|
||||
switch( im->BandFmt ) {
|
||||
case IM_BANDFMT_UCHAR:
|
||||
case IM_BANDFMT_CHAR:
|
||||
case IM_BANDFMT_USHORT:
|
||||
case IM_BANDFMT_SHORT:
|
||||
case IM_BANDFMT_UINT:
|
||||
case IM_BANDFMT_INT:
|
||||
case IM_BANDFMT_FLOAT:
|
||||
case IM_BANDFMT_DOUBLE:
|
||||
return( 1 );
|
||||
|
||||
case IM_BANDFMT_COMPLEX:
|
||||
case IM_BANDFMT_DPCOMPLEX:
|
||||
return( 0 );
|
||||
|
||||
default:
|
||||
error_exit( "im_isscalar: unknown image BandFmt" );
|
||||
/*NOTREACHED*/
|
||||
return( -1 );
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
im_iscomplex( IMAGE *im )
|
||||
{
|
||||
switch( im->BandFmt ) {
|
||||
case IM_BANDFMT_COMPLEX:
|
||||
case IM_BANDFMT_DPCOMPLEX:
|
||||
return( 1 );
|
||||
|
||||
case IM_BANDFMT_UCHAR:
|
||||
case IM_BANDFMT_CHAR:
|
||||
case IM_BANDFMT_USHORT:
|
||||
case IM_BANDFMT_SHORT:
|
||||
case IM_BANDFMT_UINT:
|
||||
case IM_BANDFMT_INT:
|
||||
case IM_BANDFMT_FLOAT:
|
||||
case IM_BANDFMT_DOUBLE:
|
||||
return( 0 );
|
||||
|
||||
default:
|
||||
error_exit( "im_iscomplex: unknown image BandFmt" );
|
||||
/*NOTREACHED*/
|
||||
return( -1 );
|
||||
}
|
||||
}
|
||||
|
||||
/* Read a few bytes from the start of a file. For sniffing file types.
|
||||
*/
|
||||
static int
|
||||
get_bytes( const char *filename, unsigned char buf[], int len )
|
||||
{
|
||||
int fd;
|
||||
|
||||
/* File may not even exist (for tmp images for example!)
|
||||
* so no hasty messages. And the file might be truncated, so no error
|
||||
* on read either.
|
||||
*/
|
||||
#ifdef BINARY_OPEN
|
||||
if( (fd = open( filename, O_RDONLY | O_BINARY )) == -1 )
|
||||
#else /*BINARY_OPEN*/
|
||||
if( (fd = open( filename, O_RDONLY )) == -1 )
|
||||
#endif /*BINARY_OPEN*/
|
||||
return( 0 );
|
||||
if( read( fd, buf, len ) != len ) {
|
||||
close( fd );
|
||||
return( 0 );
|
||||
}
|
||||
close( fd );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
int
|
||||
im_istiff( const char *filename )
|
||||
{
|
||||
unsigned char buf[2];
|
||||
|
||||
if( get_bytes( filename, buf, 2 ) )
|
||||
if( (buf[0] == 'M' && buf[1] == 'M') ||
|
||||
(buf[0] == 'I' && buf[1] == 'I') )
|
||||
return( 1 );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#ifdef HAVE_PNG
|
||||
int
|
||||
im_ispng( const char *filename )
|
||||
{
|
||||
unsigned char buf[8];
|
||||
|
||||
return( get_bytes( filename, buf, 8 ) &&
|
||||
!png_sig_cmp( buf, 0, 8 ) );
|
||||
}
|
||||
#else /*HAVE_PNG*/
|
||||
int
|
||||
im_ispng( const char *filename )
|
||||
{
|
||||
return( 0 );
|
||||
}
|
||||
#endif /*HAVE_PNG*/
|
||||
|
||||
#ifdef HAVE_MAGICK
|
||||
int
|
||||
im_ismagick( const char *filename )
|
||||
{
|
||||
IMAGE *im;
|
||||
int result;
|
||||
|
||||
if( !(im = im_open( "dummy", "p" )) )
|
||||
return( -1 );
|
||||
result = im_magick2vips_header( filename, im );
|
||||
im_clear_error_string();
|
||||
im_close( im );
|
||||
|
||||
return( result == 0 );
|
||||
}
|
||||
#else /*HAVE_MAGICK*/
|
||||
int
|
||||
im_ismagick( const char *filename )
|
||||
{
|
||||
return( 0 );
|
||||
}
|
||||
#endif /*HAVE_MAGICK*/
|
||||
|
||||
int
|
||||
im_isppm( const char *filename )
|
||||
{
|
||||
unsigned char buf[2];
|
||||
|
||||
if( get_bytes( filename, buf, 2 ) )
|
||||
if( buf[0] == 'P' && (buf[1] >= '1' || buf[1] <= '6') )
|
||||
return( 1 );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#ifdef HAVE_TIFF
|
||||
|
||||
/* Handle TIFF errors here.
|
||||
*/
|
||||
static void
|
||||
vhandle( char *module, char *fmt, ... )
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
im_errormsg( "TIFF error in \"%s\": ", module );
|
||||
|
||||
va_start( ap, fmt );
|
||||
im_verrormsg( fmt, ap );
|
||||
va_end( ap );
|
||||
}
|
||||
|
||||
int
|
||||
im_istifftiled( const char *filename )
|
||||
{
|
||||
TIFF *tif;
|
||||
int tiled;
|
||||
|
||||
/* Override the default TIFF error handler.
|
||||
*/
|
||||
TIFFSetErrorHandler( (TIFFErrorHandler) vhandle );
|
||||
|
||||
#ifdef BINARY_OPEN
|
||||
if( !(tif = TIFFOpen( filename, "rb" )) ) {
|
||||
#else /*BINARY_OPEN*/
|
||||
if( !(tif = TIFFOpen( filename, "r" )) ) {
|
||||
#endif /*BINARY_OPEN*/
|
||||
/* Not a TIFF file ... return False.
|
||||
*/
|
||||
im_clear_error_string();
|
||||
return( 0 );
|
||||
}
|
||||
tiled = TIFFIsTiled( tif );
|
||||
TIFFClose( tif );
|
||||
|
||||
return( tiled );
|
||||
}
|
||||
|
||||
#else /*HAVE_TIFF*/
|
||||
|
||||
int
|
||||
im_istifftiled( const char *filename )
|
||||
{
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif /*HAVE_TIFF*/
|
||||
|
||||
int
|
||||
im_isjpeg( const char *filename )
|
||||
{
|
||||
unsigned char buf[2];
|
||||
|
||||
if( get_bytes( filename, buf, 2 ) )
|
||||
if( (int) buf[0] == 0xff && (int) buf[1] == 0xd8 )
|
||||
return( 1 );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int
|
||||
im_isvips( const char *filename )
|
||||
{
|
||||
unsigned char buf[4];
|
||||
|
||||
if( get_bytes( filename, buf, 4 ) ) {
|
||||
if( buf[0] == 0x08 && buf[1] == 0xf2 &&
|
||||
buf[2] == 0xa6 && buf[3] == 0xb6 )
|
||||
/* SPARC-order VIPS image.
|
||||
*/
|
||||
return( 1 );
|
||||
else if( buf[3] == 0x08 && buf[2] == 0xf2 &&
|
||||
buf[1] == 0xa6 && buf[0] == 0xb6 )
|
||||
/* INTEL-order VIPS image.
|
||||
*/
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int
|
||||
im_isexr( const char *filename )
|
||||
{
|
||||
unsigned char buf[4];
|
||||
|
||||
if( get_bytes( filename, buf, 4 ) )
|
||||
if( buf[0] == 0x76 && buf[1] == 0x2f &&
|
||||
buf[2] == 0x31 && buf[3] == 0x01 )
|
||||
return( 1 );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/* Test for file exists.
|
||||
*/
|
||||
int
|
||||
im_existsf( const char *name, ... )
|
||||
{
|
||||
va_list ap;
|
||||
char buf1[PATH_MAX];
|
||||
|
||||
va_start( ap, name );
|
||||
(void) im_vsnprintf( buf1, PATH_MAX - 1, name, ap );
|
||||
va_end( ap );
|
||||
|
||||
/* Try that.
|
||||
*/
|
||||
if( !access( buf1, R_OK ) )
|
||||
return( 1 );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/* True if this IMAGE is a disc file of some sort.
|
||||
*/
|
||||
int
|
||||
im_isfile( IMAGE *im )
|
||||
{
|
||||
switch( im->dtype ) {
|
||||
case IM_MMAPIN:
|
||||
case IM_MMAPINRW:
|
||||
case IM_OPENOUT:
|
||||
case IM_OPENIN:
|
||||
return( 1 );
|
||||
|
||||
case IM_PARTIAL:
|
||||
case IM_SETBUF:
|
||||
case IM_SETBUF_FOREIGN:
|
||||
case IM_NONE:
|
||||
return( 0 );
|
||||
|
||||
default:
|
||||
error_exit( "im_isfile: corrupt IMAGE descriptor" );
|
||||
/*NOTREACHED*/
|
||||
return( -1 );
|
||||
}
|
||||
}
|
||||
|
||||
/* True if this IMAGE is a partial of some sort.
|
||||
*/
|
||||
int
|
||||
im_ispartial( IMAGE *im )
|
||||
{
|
||||
switch( im->dtype ) {
|
||||
case IM_PARTIAL:
|
||||
return( 1 );
|
||||
|
||||
case IM_SETBUF:
|
||||
case IM_SETBUF_FOREIGN:
|
||||
case IM_MMAPIN:
|
||||
case IM_MMAPINRW:
|
||||
case IM_OPENIN:
|
||||
case IM_OPENOUT:
|
||||
case IM_NONE:
|
||||
return( 0 );
|
||||
|
||||
default:
|
||||
error_exit( "im_ispartial: corrupt IMAGE descriptor" );
|
||||
/*NOTREACHED*/
|
||||
return( -1 );
|
||||
}
|
||||
}
|
||||
|
||||
/* True if an int is a power of two ... 1, 2, 4, 8, 16, 32, etc. Do with just
|
||||
* integer arithmetic for portability. A previous Nicos version using doubles
|
||||
* and log/log failed on x86 with rounding problems. Return 0 for not
|
||||
* power of two, otherwise return the position of the set bit (numbering with
|
||||
* bit 1 as the lsb).
|
||||
*/
|
||||
int
|
||||
im_ispoweroftwo( int p )
|
||||
{
|
||||
int i, n;
|
||||
|
||||
/* Count set bits. Could use a LUT, I guess.
|
||||
*/
|
||||
for( i = 0, n = 0; p; i++, p >>= 1 )
|
||||
if( (p & 1) == 1 )
|
||||
n++;
|
||||
|
||||
/* Should be just one set bit.
|
||||
*/
|
||||
if( n == 1 )
|
||||
/* Return position of bit.
|
||||
*/
|
||||
return( i );
|
||||
else
|
||||
return( 0 );
|
||||
}
|
@ -61,6 +61,7 @@ extern im_package im__boolean;
|
||||
extern im_package im__colour;
|
||||
extern im_package im__conversion;
|
||||
extern im_package im__convolution;
|
||||
extern im_package im__format;
|
||||
extern im_package im__freq_filt;
|
||||
extern im_package im__histograms_lut;
|
||||
extern im_package im__inplace;
|
||||
@ -405,6 +406,7 @@ static im_package *built_in[] = {
|
||||
&im__colour,
|
||||
&im__conversion,
|
||||
&im__convolution,
|
||||
&im__format,
|
||||
&im__freq_filt,
|
||||
&im__histograms_lut,
|
||||
&im__inplace,
|
||||
|
Loading…
Reference in New Issue
Block a user