doc fixes, new im_subtract

This commit is contained in:
John Cupitt 2009-08-18 14:12:12 +00:00
parent 345b611401
commit af3489558e
9 changed files with 180 additions and 152 deletions

View File

@ -12,7 +12,7 @@ rm -f swig/vipsCC/*.cxx
rm -f swig/vipsCC/VImage.h rm -f swig/vipsCC/VImage.h
rm -f swig/vipsCC/VImage.py python/vipsCC/VError.py python/vipsCC/VMask.py python/vipsCC/Display.py rm -f swig/vipsCC/VImage.py python/vipsCC/VError.py python/vipsCC/VMask.py python/vipsCC/Display.py
rm -f benchmark/temp* rm -f benchmark/temp*
( cd doc ; mkdir poop ; mv reference/VIPS-docs.sgml.in poop ; mv reference/Makefile.am poop ; rm -rf reference/* ; mv poop/* reference ; rmdir poop ) ( cd doc ; mkdir poop ; mv reference/libvips-docs.sgml.in poop ; mv reference/Makefile.am poop ; rm -rf reference/* ; mv poop/* reference ; rmdir poop )
gtkdocize --copy --docdir doc/reference --flavour no-tmpl || exit 1 gtkdocize --copy --docdir doc/reference --flavour no-tmpl || exit 1

View File

@ -548,7 +548,7 @@ AC_OUTPUT([
man/Makefile man/Makefile
doc/Makefile doc/Makefile
doc/reference/Makefile doc/reference/Makefile
doc/reference/VIPS-docs.sgml doc/reference/libvips-docs.sgml
po/Makefile.in po/Makefile.in
]) ])

View File

@ -9,10 +9,12 @@ AUTOMAKE_OPTIONS = 1.6
# of using the various options. # of using the various options.
# The name of the module, e.g. 'glib'. # The name of the module, e.g. 'glib'.
DOC_MODULE=VIPS # (vips: we put the version in the module name rather than defining
# DOC_MODULE_VERSION to avoid some broken links)
DOC_MODULE=libvips
# Uncomment for versioned docs and specify the version of the module, e.g. '2'. # Uncomment for versioned docs and specify the version of the module, e.g. '2'.
DOC_MODULE_VERSION=7 #DOC_MODULE_VERSION=7
# The top-level SGML file. You can change this if you want to. # The top-level SGML file. You can change this if you want to.
DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.sgml DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.sgml
@ -92,10 +94,10 @@ include $(top_srcdir)/gtk-doc.make
# Files not to distribute # Files not to distribute
# for --rebuild-types in $(SCAN_OPTIONS), e.g. $(DOC_MODULE).types # for --rebuild-types in $(SCAN_OPTIONS), e.g. $(DOC_MODULE).types
# for --rebuild-sections in $(SCAN_OPTIONS) e.g. $(DOC_MODULE)-sections.txt # for --rebuild-sections in $(SCAN_OPTIONS) e.g. $(DOC_MODULE)-sections.txt
DISTCLEANFILES = VIPS.types DISTCLEANFILES = libvips.types
# Comment this out if you want your docs-status tested during 'make check' # Comment this out if you want your docs-status tested during 'make check'
if ENABLE_GTK_DOC if ENABLE_GTK_DOC
#TESTS_ENVIRONMENT = cd $(srcsrc) TESTS_ENVIRONMENT = cd $(srcsrc)
#TESTS = $(GTKDOC_CHECK) TESTS = $(GTKDOC_CHECK)
endif endif

View File

@ -53,7 +53,7 @@
* These operations perform pixel arithmetic, that is, they perform an * These operations perform pixel arithmetic, that is, they perform an
* arithmetic operation, such as addition, on every pixel in an image or a * arithmetic operation, such as addition, on every pixel in an image or a
* pair of images. All (except in a few cases noted below) will work with * pair of images. All (except in a few cases noted below) will work with
* images of any type (or any mixture of types), of any size and of any number * images of any type or any mixture of types, of any size and of any number
* of bands. * of bands.
* *
* For binary operations, if the number of bands differs, one of the images * For binary operations, if the number of bands differs, one of the images

View File

@ -20,6 +20,11 @@
* - ... so 1 band + 4 band image -> 4 band image * - ... so 1 band + 4 band image -> 4 band image
* 8/12/06 * 8/12/06
* - add liboil support * - add liboil support
* 18/8/08
* - revise upcasting system
* - im__cast_and_call() no longer sets bbits for you
* - add gtkdoc comments
* - remove separate complex case, just double size
*/ */
/* /*
@ -69,33 +74,7 @@
#include <dmalloc.h> #include <dmalloc.h>
#endif /*WITH_DMALLOC*/ #endif /*WITH_DMALLOC*/
/* Complex add. #define LOOP( IN, OUT ) { \
*/
#define cloop(TYPE) { \
TYPE *p1 = (TYPE *) in[0]; \
TYPE *p2 = (TYPE *) in[1]; \
TYPE *q = (TYPE *) out; \
\
for( x = 0; x < sz; x++ ) { \
double rp1 = p1[0]; \
double ip1 = p1[1]; \
\
double rp2 = p2[0]; \
double ip2 = p2[1]; \
\
p1 += 2; \
p2 += 2; \
\
q[0] = rp1 + rp2; \
q[1] = ip1 + ip2; \
\
q += 2; \
} \
}
/* Real add.
*/
#define rloop(IN, OUT) { \
IN *p1 = (IN *) in[0]; \ IN *p1 = (IN *) in[0]; \
IN *p2 = (IN *) in[1]; \ IN *p2 = (IN *) in[1]; \
OUT *q = (OUT *) out; \ OUT *q = (OUT *) out; \
@ -107,31 +86,35 @@
static void static void
add_buffer( PEL **in, PEL *out, int width, IMAGE *im ) add_buffer( PEL **in, PEL *out, int width, IMAGE *im )
{ {
int x; /* Complex just doubles the size.
int sz = width * im->Bands; */
const int sz = width * im->Bands * (im_iscomplex( im ) ? 2 : 1);
/* Add all input types. Kep types here in sync with bandfmt_add[] below. int x;
/* Add all input types. Keep types here in sync with bandfmt_add[]
* below.
*/ */
switch( im->BandFmt ) { switch( im->BandFmt ) {
case IM_BANDFMT_UCHAR: rloop( unsigned char, unsigned short ); break; case IM_BANDFMT_UCHAR: LOOP( unsigned char, unsigned short ); break;
case IM_BANDFMT_CHAR: rloop( signed char, signed short ); break; case IM_BANDFMT_CHAR: LOOP( signed char, signed short ); break;
case IM_BANDFMT_USHORT: rloop( unsigned short, unsigned int ); break; case IM_BANDFMT_USHORT: LOOP( unsigned short, unsigned int ); break;
case IM_BANDFMT_SHORT: rloop( signed short, signed int ); break; case IM_BANDFMT_SHORT: LOOP( signed short, signed int ); break;
case IM_BANDFMT_UINT: rloop( unsigned int, unsigned int ); break; case IM_BANDFMT_UINT: LOOP( unsigned int, unsigned int ); break;
case IM_BANDFMT_INT: rloop( signed int, signed int ); break; case IM_BANDFMT_INT: LOOP( signed int, signed int ); break;
case IM_BANDFMT_FLOAT: case IM_BANDFMT_FLOAT:
#ifdef HAVE_LIBOIL #ifdef HAVE_LIBOIL
oil_add_f32( (float *) out, oil_add_f32( (float *) out,
(float *) in[0], (float *) in[1], sz ); (float *) in[0], (float *) in[1], sz );
#else /*!HAVE_LIBOIL*/ #else /*!HAVE_LIBOIL*/
rloop( float, float ); LOOP( float, float );
#endif /*HAVE_LIBOIL*/ #endif /*HAVE_LIBOIL*/
break; break;
case IM_BANDFMT_DOUBLE: rloop( double, double ); break; case IM_BANDFMT_DOUBLE: LOOP( double, double ); break;
case IM_BANDFMT_COMPLEX:cloop( float ); break; case IM_BANDFMT_COMPLEX:LOOP( float, float ); break;
case IM_BANDFMT_DPCOMPLEX:cloop( double ); break; case IM_BANDFMT_DPCOMPLEX:LOOP( double, double ); break;
default: default:
assert( 0 ); assert( 0 );
@ -147,9 +130,9 @@ add_buffer( PEL **in, PEL *out, int width, IMAGE *im )
#define UI IM_BANDFMT_UINT #define UI IM_BANDFMT_UINT
#define I IM_BANDFMT_INT #define I IM_BANDFMT_INT
#define F IM_BANDFMT_FLOAT #define F IM_BANDFMT_FLOAT
#define M IM_BANDFMT_COMPLEX #define X IM_BANDFMT_COMPLEX
#define D IM_BANDFMT_DOUBLE #define D IM_BANDFMT_DOUBLE
#define DM IM_BANDFMT_DPCOMPLEX #define DX IM_BANDFMT_DPCOMPLEX
/* For two integer types, the "largest", ie. one which can represent the /* For two integer types, the "largest", ie. one which can represent the
* full range of both. * full range of both.
@ -166,7 +149,7 @@ static int bandfmt_largest[6][6] = {
/* For two formats, find one which can represent the full range of both. /* For two formats, find one which can represent the full range of both.
*/ */
static VipsBandFmt VipsBandFmt
im__format_common( IMAGE *in1, IMAGE *in2 ) im__format_common( IMAGE *in1, IMAGE *in2 )
{ {
if( im_iscomplex( in1 ) || im_iscomplex( in2 ) ) { if( im_iscomplex( in1 ) || im_iscomplex( in2 ) ) {
@ -260,8 +243,8 @@ im__cast_and_call( IMAGE *in1, IMAGE *in2, IMAGE *out,
* match the case statement in add_buffer() above. * match the case statement in add_buffer() above.
*/ */
static int bandfmt_add[10] = { static int bandfmt_add[10] = {
/* UC C US S UI I F M D DM */ /* UC C US S UI I F X D DX */
US, S, UI, I, UI, I, F, M, D, DM US, S, UI, I, UI, I, F, X, D, DX
}; };
/** /**
@ -270,10 +253,13 @@ static int bandfmt_add[10] = {
* @in2: input image 2 * @in2: input image 2
* @out: output image * @out: output image
* *
* This operation adds corresponding pixels in images @in1 and * This operation calculates @in1 + @in2 and writes the result to @out.
* @in2 and writes the result to the image descriptor @out. The images must be * The images must be the same size. They may have any format.
* the same size, but may have any type. If one of the images has a single *
* band, it is added to every band of the other image. * If the number of bands differs, one of the images
* must have one band. In this case, an n-band image is formed from the
* one-band image by joining n copies of the one-band image together, and then
* the two n-band images are operated upon.
* *
* The two input images are cast up to the smallest common type (see table * The two input images are cast up to the smallest common type (see table
* Smallest common format in * Smallest common format in

View File

@ -32,6 +32,10 @@
* - updated for 1 band $op n band image -> n band image case * - updated for 1 band $op n band image -> n band image case
* 8/12/06 * 8/12/06
* - add liboil support * - add liboil support
* 18/8/08
* - revise upcasting system
* - add gtkdoc comments
* - remove separate complex case, just double size
*/ */
/* /*
@ -81,70 +85,46 @@
#include <dmalloc.h> #include <dmalloc.h>
#endif /*WITH_DMALLOC*/ #endif /*WITH_DMALLOC*/
/* Complex subtract. #define LOOP( IN, OUT ) { \
*/ IN *p1 = (IN *) in[0]; \
#define cloop(TYPE) \ IN *p2 = (IN *) in[1]; \
{\ OUT *q = (OUT *) out; \
TYPE *p1 = (TYPE *) in[0];\
TYPE *p2 = (TYPE *) in[1];\
TYPE *q = (TYPE *) out;\
\ \
for( x = 0; x < sz; x++ ) {\ for( x = 0; x < sz; x++ ) \
double rp1 = p1[0];\ q[x] = p1[x] - p2[x]; \
double ip1 = p1[1];\
\
double rp2 = p2[0];\
double ip2 = p2[1];\
\
p1 += 2;\
p2 += 2;\
\
q[0] = rp1 - rp2;\
q[1] = ip1 - ip2;\
\
q += 2;\
}\
}
/* Real subtract.
*/
#define rloop(TYPE) \
{\
TYPE *p1 = (TYPE *) in[0];\
TYPE *p2 = (TYPE *) in[1];\
TYPE *q = (TYPE *) out;\
\
for( x = 0; x < sz; x++ )\
q[x] = p1[x] - p2[x];\
} }
static void static void
subtract_buffer( PEL **in, PEL *out, int width, IMAGE *im ) subtract_buffer( PEL **in, PEL *out, int width, IMAGE *im )
{ {
int x; /* Complex just doubles the size.
int sz = width * im->Bands; */
const int sz = width * im->Bands * (im_iscomplex( im ) ? 2 : 1);
/* Subtract all input types. int x;
/* Add all input types. Keep types here in sync with bandfmt_subtract[]
* below.
*/ */
switch( im->BandFmt ) { switch( im->BandFmt ) {
case IM_BANDFMT_CHAR: rloop( signed char ); break; case IM_BANDFMT_CHAR: LOOP( signed char, signed short ); break;
case IM_BANDFMT_UCHAR: rloop( unsigned char ); break; case IM_BANDFMT_UCHAR: LOOP( unsigned char, signed short ); break;
case IM_BANDFMT_SHORT: rloop( signed short ); break; case IM_BANDFMT_SHORT: LOOP( signed short, signed int ); break;
case IM_BANDFMT_USHORT: rloop( unsigned short ); break; case IM_BANDFMT_USHORT: LOOP( unsigned short, signed int ); break;
case IM_BANDFMT_INT: rloop( signed int ); break; case IM_BANDFMT_INT: LOOP( signed int, signed int ); break;
case IM_BANDFMT_UINT: rloop( unsigned int ); break; case IM_BANDFMT_UINT: LOOP( unsigned int, signed int ); break;
case IM_BANDFMT_FLOAT: case IM_BANDFMT_FLOAT:
#ifdef HAVE_LIBOIL #ifdef HAVE_LIBOIL
oil_subtract_f32( (float *) out, oil_subtract_f32( (float *) out,
(float *) in[0], (float *) in[1], sz ); (float *) in[0], (float *) in[1], sz );
#else /*!HAVE_LIBOIL*/ #else /*!HAVE_LIBOIL*/
rloop( float ); LOOP( float, float );
#endif /*HAVE_LIBOIL*/ #endif /*HAVE_LIBOIL*/
break; break;
case IM_BANDFMT_DOUBLE: rloop( double ); break; case IM_BANDFMT_DOUBLE: LOOP( double, double ); break;
case IM_BANDFMT_COMPLEX: cloop( float ); break; case IM_BANDFMT_COMPLEX:LOOP( float, float ); break;
case IM_BANDFMT_DPCOMPLEX: cloop( double ); break; case IM_BANDFMT_DPCOMPLEX:LOOP( double, double ); break;
default: default:
assert( 0 ); assert( 0 );
@ -153,40 +133,115 @@ subtract_buffer( PEL **in, PEL *out, int width, IMAGE *im )
/* Save a bit of typing. /* Save a bit of typing.
*/ */
#define UC IM_BANDFMT_UCHAR
#define C IM_BANDFMT_CHAR
#define US IM_BANDFMT_USHORT
#define S IM_BANDFMT_SHORT #define S IM_BANDFMT_SHORT
#define UI IM_BANDFMT_UINT
#define I IM_BANDFMT_INT #define I IM_BANDFMT_INT
#define F IM_BANDFMT_FLOAT
#define X IM_BANDFMT_COMPLEX
#define D IM_BANDFMT_DOUBLE #define D IM_BANDFMT_DOUBLE
#define DX IM_BANDFMT_DPCOMPLEX
/* Type conversions for two integer inputs. Rules for float and complex /* Type promotion for subtraction. Sign and value preserving. Make sure these
* input encoded with ifs. We are sign and value preserving. * match the case statement in subtract_buffer() above.
*/ */
static int iformat[6][6] = { static int bandfmt_subtract[10] = {
/* UC C US S UI I */ /* UC C US S UI I F X D DX */
/* UC */ { S, S, I, I, I, I }, S, S, I, I, I, I, F, X, D, DX
/* C */ { S, S, I, I, I, I },
/* US */ { I, I, I, I, I, I },
/* S */ { I, I, I, I, I, I },
/* UI */ { I, I, I, I, I, I },
/* I */ { I, I, I, I, I, I }
}; };
/**
* im_subtract:
* @in1: input image 1
* @in2: input image 2
* @out: output image
*
* This operation calculates @in1 - @in2 and writes the result to @out.
* The images must be the same size. They may have any format.
*
* If the number of bands differs, one of the images
* must have one band. In this case, an n-band image is formed from the
* one-band image by joining n copies of the one-band image together, and then
* the two n-band images are operated upon.
*
* The two input images are cast up to the smallest common type (see table
* Smallest common format in
* <link linkend="VIPS-arithmetic">arithmetic</link>), then the
* following table is used to determine the output type:
*
* <table>
* <title>im_subtract() type promotion</title>
* <tgroup cols='2' align='left' colsep='1' rowsep='1'>
* <thead>
* <row>
* <entry>input type</entry>
* <entry>output type</entry>
* </row>
* </thead>
* <tbody>
* <row>
* <entry>uchar</entry>
* <entry>short</entry>
* </row>
* <row>
* <entry>char</entry>
* <entry>short</entry>
* </row>
* <row>
* <entry>ushort</entry>
* <entry>int</entry>
* </row>
* <row>
* <entry>short</entry>
* <entry>int</entry>
* </row>
* <row>
* <entry>uint</entry>
* <entry>int</entry>
* </row>
* <row>
* <entry>int</entry>
* <entry>int</entry>
* </row>
* <row>
* <entry>float</entry>
* <entry>float</entry>
* </row>
* <row>
* <entry>double</entry>
* <entry>double</entry>
* </row>
* <row>
* <entry>complex</entry>
* <entry>complex</entry>
* </row>
* <row>
* <entry>double complex</entry>
* <entry>double complex</entry>
* </row>
* </tbody>
* </tgroup>
* </table>
*
* In other words, the output type is just large enough to hold the whole
* range of possible values.
*
* See also: im_add(), im_lintra().
*
* Returns: 0 on success, -1 on error
*/
int int
im_subtract( IMAGE *in1, IMAGE *in2, IMAGE *out ) im_subtract( IMAGE *in1, IMAGE *in2, IMAGE *out )
{ {
/* Basic checks. if( im_piocheck( in1, out ) ||
*/ im_pincheck( in2 ) ||
if( im_piocheck( in1, out ) || im_pincheck( in2 ) ) im_check_bands_1orn( "im_subtract", in1, in2 ) ||
im_check_uncoded( "im_subtract", in1 ) ||
im_check_uncoded( "im_subtract", in2 ) )
return( -1 ); return( -1 );
if( in1->Bands != in2->Bands &&
(in1->Bands != 1 && in2->Bands != 1) ) {
im_error( "im_subtract",
"%s", _( "not same number of bands" ) );
return( -1 );
}
if( in1->Coding != IM_CODING_NONE || in2->Coding != IM_CODING_NONE ) {
im_error( "im_subtract", "%s", _( "not uncoded" ) );
return( -1 );
}
if( im_cp_descv( out, in1, in2, NULL ) ) if( im_cp_descv( out, in1, in2, NULL ) )
return( -1 ); return( -1 );
@ -196,30 +251,8 @@ im_subtract( IMAGE *in1, IMAGE *in2, IMAGE *out )
/* What output type will we write? int, float or complex. /* What output type will we write? int, float or complex.
*/ */
if( im_iscomplex( in1 ) || im_iscomplex( in2 ) ) { out->BandFmt = bandfmt_subtract[im__format_common( in1, in2 )];
/* What kind of complex? out->Bbits = im_bits_of_fmt( out->BandFmt );
*/
if( in1->BandFmt == IM_BANDFMT_DPCOMPLEX ||
in2->BandFmt == IM_BANDFMT_DPCOMPLEX )
/* Output will be DPCOMPLEX.
*/
out->BandFmt = IM_BANDFMT_DPCOMPLEX;
else
out->BandFmt = IM_BANDFMT_COMPLEX;
}
else if( im_isfloat( in1 ) || im_isfloat( in2 ) ) {
/* What kind of float?
*/
if( in1->BandFmt == IM_BANDFMT_DOUBLE ||
in2->BandFmt == IM_BANDFMT_DOUBLE )
out->BandFmt = IM_BANDFMT_DOUBLE;
else
out->BandFmt = IM_BANDFMT_FLOAT;
}
else
/* Must be int+int -> int.
*/
out->BandFmt = iformat[in1->BandFmt][in2->BandFmt];
/* And process! /* And process!
*/ */

View File

@ -27,6 +27,8 @@
* - write CMYK if Bands == 4 and Type == CMYK * - write CMYK if Bands == 4 and Type == CMYK
* 12/5/09 * 12/5/09
* - fix signed/unsigned warning * - fix signed/unsigned warning
* 13/8/09
* - allow "none" for profile, meaning don't embed one
*/ */
/* /*
@ -612,8 +614,10 @@ write_vips( Write *write, int qfac, const char *profile )
return( -1 ); return( -1 );
/* A profile supplied as an argument overrides an embedded profile. /* A profile supplied as an argument overrides an embedded profile.
* "none" means don't attach a profile.
*/ */
if( profile && if( profile &&
strcmp( profile, "none" ) != 0 &&
write_profile_file( write, profile ) ) write_profile_file( write, profile ) )
return( -1 ); return( -1 );
if( !profile && if( !profile &&

View File

@ -131,7 +131,10 @@ char *im__gslist_gvalue_get( const GSList *list );
void im__buffer_init( void ); void im__buffer_init( void );
int im__cast_and_call(); int im__cast_and_call( IMAGE *in1, IMAGE *in2, IMAGE *out,
im_wrapmany_fn fn, void *a );
VipsBandFmt im__format_common( IMAGE *in1, IMAGE *in2 );
int im__test_kill( IMAGE *im ); int im__test_kill( IMAGE *im );
void *im__mmap( int fd, int writeable, size_t length, gint64 offset ); void *im__mmap( int fd, int writeable, size_t length, gint64 offset );
int im__munmap( void *start, size_t length ); int im__munmap( void *start, size_t length );