rot45 works

This commit is contained in:
John Cupitt 2013-10-19 18:26:46 +01:00
parent 0a0ebb352c
commit 67dff74b2c
11 changed files with 194 additions and 99 deletions

View File

@ -2,7 +2,7 @@
# also update the version number in the m4 macros below # also update the version number in the m4 macros below
AC_INIT([vips], [7.36.3], [vipsip@jiscmail.ac.uk]) AC_INIT([vips], [7.37.0], [vipsip@jiscmail.ac.uk])
# required for gobject-introspection # required for gobject-introspection
AC_PREREQ(2.62) AC_PREREQ(2.62)
@ -16,8 +16,8 @@ AC_CONFIG_MACRO_DIR([m4])
# user-visible library versioning # user-visible library versioning
m4_define([vips_major_version], [7]) m4_define([vips_major_version], [7])
m4_define([vips_minor_version], [36]) m4_define([vips_minor_version], [37])
m4_define([vips_micro_version], [3]) m4_define([vips_micro_version], [0])
m4_define([vips_version], m4_define([vips_version],
[vips_major_version.vips_minor_version.vips_micro_version]) [vips_major_version.vips_minor_version.vips_micro_version])
@ -36,9 +36,9 @@ VIPS_VERSION_STRING=$VIPS_VERSION-`date`
# binary interface changes backwards compatible?: increment age # binary interface changes backwards compatible?: increment age
# binary interface changes not backwards compatible?: reset age to 0 # binary interface changes not backwards compatible?: reset age to 0
LIBRARY_CURRENT=35 LIBRARY_CURRENT=36
LIBRARY_REVISION=3 LIBRARY_REVISION=0
LIBRARY_AGE=0 LIBRARY_AGE=1
# patched into include/vips/version.h # patched into include/vips/version.h
AC_SUBST(VIPS_VERSION) AC_SUBST(VIPS_VERSION)

View File

@ -23,6 +23,7 @@ libconversion_la_SOURCES = \
bandary.h \ bandary.h \
bandary.c \ bandary.c \
rot.c \ rot.c \
rot45.c \
ifthenelse.c \ ifthenelse.c \
falsecolour.c \ falsecolour.c \
msb.c \ msb.c \

View File

@ -212,6 +212,7 @@ vips_conversion_operation_init( void )
extern GType vips_bandjoin_get_type( void ); extern GType vips_bandjoin_get_type( void );
extern GType vips_black_get_type( void ); extern GType vips_black_get_type( void );
extern GType vips_rot_get_type( void ); extern GType vips_rot_get_type( void );
extern GType vips_rot45_get_type( void );
extern GType vips_ifthenelse_get_type( void ); extern GType vips_ifthenelse_get_type( void );
extern GType vips_recomb_get_type( void ); extern GType vips_recomb_get_type( void );
extern GType vips_bandmean_get_type( void ); extern GType vips_bandmean_get_type( void );
@ -247,6 +248,7 @@ vips_conversion_operation_init( void )
vips_bandjoin_get_type(); vips_bandjoin_get_type();
vips_black_get_type(); vips_black_get_type();
vips_rot_get_type(); vips_rot_get_type();
vips_rot45_get_type();
vips_ifthenelse_get_type(); vips_ifthenelse_get_type();
vips_recomb_get_type(); vips_recomb_get_type();
vips_bandmean_get_type(); vips_bandmean_get_type();

View File

@ -1,4 +1,4 @@
/* 'lossless' 45 degree rot45ate ... odd-sized square images only /* 'lossless' 45 degree rotate ... odd-sized square images only
* *
* Author: N. Dessipris (Copyright, N. Dessipris 1991) * Author: N. Dessipris (Copyright, N. Dessipris 1991)
* Written on: 08/05/1991 * Written on: 08/05/1991
@ -13,7 +13,7 @@
* 1/12/10 * 1/12/10
* - allow any size mask for the 90 degree rot45ates by using im_rot4590(). * - allow any size mask for the 90 degree rot45ates by using im_rot4590().
* 12/10/13 * 12/10/13
* - redone as a class from im_offsets45() * - rewritten as a class
*/ */
/* /*
@ -73,99 +73,115 @@ typedef struct _VipsRot45 {
*/ */
VipsAngle45 angle; VipsAngle45 angle;
/* Output memory buffer ... copy this to ->out.
*/
VipsImage *outbuf;
} VipsRot45; } VipsRot45;
typedef VipsConversionClass VipsRot45Class; typedef VipsConversionClass VipsRot45Class;
G_DEFINE_TYPE( VipsRot45, vips_rot45, VIPS_TYPE_CONVERSION ); G_DEFINE_TYPE( VipsRot45, vips_rot45, VIPS_TYPE_CONVERSION );
#define ASSIGN( Xout, Yout, Xin, Yin ) { \
/* Creates the offsets to rotate by 45 degrees an odd size square mask VipsPel *q = VIPS_IMAGE_ADDR( out, Xout, Yout ); \
*/ VipsPel *p = VIPS_IMAGE_ADDR( in, Xin, Yin ); \
int * int b;\
im_offsets45( int size ) \
{ for( b = 0; b < ps; b++ )\
int temp; q[b] = p[b];\
int x, y;
int size2 = size * size;
int size_2 = size / 2;
int *pnt, *cpnt1, *cpnt2;
if( size%2 == 0 ) {
im_error( "im_offsets45", "%s", _( "size not odd" ) );
return( NULL );
}
if( !(pnt = IM_ARRAY( NULL, size2, int )) )
return( NULL );
/* point at the beginning and end of the buffer
*/
cpnt1 = pnt; cpnt2 = pnt + size2 - 1;
for( y = 0; y < size_2; y++ ) {
temp = (size_2 + y) * size;
*cpnt1++ = temp;
*cpnt2-- = size2 - 1 - temp;
for( x = 0; x < y; x++ ) {
temp -= (size-1);
*cpnt1++ = temp;
*cpnt2-- = size2 - 1 - temp;
}
for( x = 0; x < size_2 - y; x++ ) {
temp -= size;
*cpnt1++ = temp;
*cpnt2-- = size2 - 1 - temp;
}
for( x = 0; x < size_2 - y; x++ ) {
temp++;
*cpnt1++ = temp;
*cpnt2-- = size2 - 1 - temp;
}
for( x = 0; x < y; x++ ) {
temp -= ( size - 1 );
*cpnt1++ = temp;
*cpnt2-- = size2 - 1 - temp;
}
}
/* the diagonal now
*/
temp = size * (size - 1);
cpnt1 = pnt + size_2 * size;
for( x = 0; x < size; x++ ) {
*cpnt1++ = temp;
temp -= (size-1);
}
#ifdef PIM_RINT
temp = 0;
for( y = 0; y < size; y++ ) {
for( x = 0; x < size; x++ ) {
fprintf( stderr, "%4d", *(pnt+temp) );
temp++;
}
fprintf(stderr, "\n");
}
fprintf(stderr, "\n");
#endif
return( pnt );
} }
#define POINT_TO_TEMP( q, Xin, Yin ) { \
VipsPel *p = VIPS_IMAGE_ADDR( in, Xin, Yin ); \
int b;\
\
for( b = 0; b < ps; b++ )\
q[b] = p[b];\
}
#define TEMP_TO_POINT( Xout, Yout, p ) { \
VipsPel *q = VIPS_IMAGE_ADDR( out, Xout, Yout ); \
int b;\
\
for( b = 0; b < ps; b++ )\
q[b] = p[b];\
}
/* This can work inplace, ie. in == out is allowed.
*/
static void static void
vips_rot45_45( VipsRot45 *rot45 ) vips_rot45_rot45( VipsImage *out, VipsImage *in )
{ {
int x, y, i; size_t ps = VIPS_IMAGE_SIZEOF_PEL( in );
VipsPel *temp = VIPS_ARRAY( in, ps, VipsPel );
int size = in->Xsize;
int size_2 = size / 2;
int x, y;
g_assert( in->Xsize == in->Ysize );
g_assert( out->Xsize == out->Ysize );
g_assert( in->Xsize == out->Ssize );
g_assert( in->Xsize % 2 == 0 );
/* Split the square into 8 triangles. Loop over the top-left one,
* reflect into the others.
*
* 1 1 2 2 3
* 8 1 2 3 3
* 8 8 x 4 4
* 7 7 6 5 4
* 7 6 6 5 5
*
* do the centre separately.
*/
for( y = 0; y < size_2; y++ )
for( x = y; x < size_2; x++ ) {
/* Save 1, it goes into 8 at the end.
*/
POINT_TO_TEMP( temp, x, y );
/* Fill 1 from 2.
*/
ASSIGN( x, y,
(x - y) + size_2, y );
/* 2 from 3.
*/
ASSIGN( (x - y) + size_2, y,
(size - 1) - y, x );
/* 3 from 4.
*/
ASSIGN( (size - 1) - y, x,
(size - 1) - y, (x - y) + size_2 );
/* 4 from 5.
*/
ASSIGN( (size - 1) - y, (x - y) + size_2,
(size - 1) - x, (size - 1) - y );
/* 5 from 6.
*/
ASSIGN( (size - 1) - x, (size - 1) - y,
size_2 - (x - y), (size - 1) - y );
/* 6 from 7.
*/
ASSIGN( size_2 - (x - y), (size - 1) - y,
y, (size - 1) - x );
/* 7 from 8.
*/
ASSIGN( y, (size - 1) - x,
y, size_2 - (x - y) );
/* 8 from saved 1.
*/
TEMP_TO_POINT( y, size_2 - (x - y), temp );
}
/* Centre.
*/
ASSIGN( size_2, size_2, size_2, size_2 );
} }
static int static int
@ -173,9 +189,11 @@ vips_rot45_build( VipsObject *object )
{ {
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object ); VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object );
VipsConversion *conversion = VIPS_CONVERSION( object ); VipsConversion *conversion = VIPS_CONVERSION( object );
VipsRot45 *rot45 = (VipsRot *) object; VipsRot45 *rot45 = (VipsRot45 *) object;
VipsImage **t = (VipsImage **) vips_object_local_array( object, 1 ); VipsImage **t = (VipsImage **) vips_object_local_array( object, 1 );
VipsImage *from;
if( VIPS_OBJECT_CLASS( vips_rot45_parent_class )->build( object ) ) if( VIPS_OBJECT_CLASS( vips_rot45_parent_class )->build( object ) )
return( -1 ); return( -1 );
@ -188,11 +206,41 @@ vips_rot45_build( VipsObject *object )
if( vips_image_wio_input( rot45->in ) ) if( vips_image_wio_input( rot45->in ) )
return( -1 ); return( -1 );
if( vips_image_copy_fields( conversion->out, rot45->in ) ) t[0] = vips_image_new_buffer();
if( vips_image_copy_fields( t[0], rot45->in ) ||
vips_image_write_prepare( t[0] ) )
return( -1 ); return( -1 );
from = rot45->in;
switch( rot45->angle ) { switch( rot45->angle ) {
case VIPS_ANGLE45_315:
vips_rot45_rot45( t[0], from );
from = t[0];
case VIPS_ANGLE45_270:
vips_rot45_rot45( t[0], from );
from = t[0];
case VIPS_ANGLE45_225:
vips_rot45_rot45( t[0], from );
from = t[0];
case VIPS_ANGLE45_180:
vips_rot45_rot45( t[0], from );
from = t[0];
case VIPS_ANGLE45_135:
vips_rot45_rot45( t[0], from );
from = t[0];
case VIPS_ANGLE45_90:
vips_rot45_rot45( t[0], from );
from = t[0];
case VIPS_ANGLE45_45: case VIPS_ANGLE45_45:
vips_rot45_rot45( t[0], from );
from = t[0];
break; break;
default: default:
@ -203,6 +251,9 @@ vips_rot45_build( VipsObject *object )
return( 0 ); return( 0 );
} }
if( vips_image_write( t[0], conversion->out ) )
return( -1 );
return( 0 ); return( 0 );
} }
@ -232,12 +283,13 @@ vips_rot45_class_init( VipsRot45Class *class )
_( "Angle to rotate image" ), _( "Angle to rotate image" ),
VIPS_ARGUMENT_REQUIRED_INPUT, VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsRot45, angle ), G_STRUCT_OFFSET( VipsRot45, angle ),
VIPS_TYPE_ANGLE45, VIPS_ANGLE_45 ); VIPS_TYPE_ANGLE45, VIPS_ANGLE45_45 );
} }
static void static void
vips_rot45_init( VipsRot45 *rot45 ) vips_rot45_init( VipsRot45 *rot45 )
{ {
rot45->angle = VIPS_ANGLE45_45;
} }
/** /**
@ -255,7 +307,7 @@ vips_rot45_init( VipsRot45 *rot45 )
* Returns: 0 on success, -1 on error * Returns: 0 on success, -1 on error
*/ */
int int
vips_rot45( VipsImage *in, VipsImage **out, VipsAngle angle, ... ) vips_rot45( VipsImage *in, VipsImage **out, VipsAngle45 angle, ... )
{ {
va_list ap; va_list ap;
int result; int result;

View File

@ -69,6 +69,18 @@ typedef enum {
VIPS_ANGLE_LAST VIPS_ANGLE_LAST
} VipsAngle; } VipsAngle;
typedef enum {
VIPS_ANGLE45_0,
VIPS_ANGLE45_45,
VIPS_ANGLE45_90,
VIPS_ANGLE45_135,
VIPS_ANGLE45_180,
VIPS_ANGLE45_225,
VIPS_ANGLE45_270,
VIPS_ANGLE45_315,
VIPS_ANGLE45_LAST
} VipsAngle45;
int vips_copy( VipsImage *in, VipsImage **out, ... ) int vips_copy( VipsImage *in, VipsImage **out, ... )
__attribute__((sentinel)); __attribute__((sentinel));
int vips_tilecache( VipsImage *in, VipsImage **out, ... ) int vips_tilecache( VipsImage *in, VipsImage **out, ... )
@ -107,6 +119,8 @@ int vips_wrap( VipsImage *in, VipsImage **out, ... )
__attribute__((sentinel)); __attribute__((sentinel));
int vips_rot( VipsImage *in, VipsImage **out, VipsAngle angle, ... ) int vips_rot( VipsImage *in, VipsImage **out, VipsAngle angle, ... )
__attribute__((sentinel)); __attribute__((sentinel));
int vips_rot45( VipsImage *in, VipsImage **out, VipsAngle45 angle, ... )
__attribute__((sentinel));
int vips_zoom( VipsImage *in, VipsImage **out, int xfac, int yfac, ... ) int vips_zoom( VipsImage *in, VipsImage **out, int xfac, int yfac, ... )
__attribute__((sentinel)); __attribute__((sentinel));
int vips_subsample( VipsImage *in, VipsImage **out, int xfac, int yfac, ... ) int vips_subsample( VipsImage *in, VipsImage **out, int xfac, int yfac, ... )

View File

@ -47,6 +47,8 @@ GType vips_align_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_ALIGN (vips_align_get_type()) #define VIPS_TYPE_ALIGN (vips_align_get_type())
GType vips_angle_get_type (void) G_GNUC_CONST; GType vips_angle_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_ANGLE (vips_angle_get_type()) #define VIPS_TYPE_ANGLE (vips_angle_get_type())
GType vips_angle45_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_ANGLE45 (vips_angle45_get_type())
/* enumerations from "../../../libvips/include/vips/util.h" */ /* enumerations from "../../../libvips/include/vips/util.h" */
GType vips_token_get_type (void) G_GNUC_CONST; GType vips_token_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_TOKEN (vips_token_get_type()) #define VIPS_TYPE_TOKEN (vips_token_get_type())

View File

@ -223,6 +223,30 @@ vips_angle_get_type( void )
return( etype ); return( etype );
} }
GType
vips_angle45_get_type( void )
{
static GType etype = 0;
if( etype == 0 ) {
static const GEnumValue values[] = {
{VIPS_ANGLE45_0, "VIPS_ANGLE45_0", "0"},
{VIPS_ANGLE45_45, "VIPS_ANGLE45_45", "45"},
{VIPS_ANGLE45_90, "VIPS_ANGLE45_90", "90"},
{VIPS_ANGLE45_135, "VIPS_ANGLE45_135", "135"},
{VIPS_ANGLE45_180, "VIPS_ANGLE45_180", "180"},
{VIPS_ANGLE45_225, "VIPS_ANGLE45_225", "225"},
{VIPS_ANGLE45_270, "VIPS_ANGLE45_270", "270"},
{VIPS_ANGLE45_315, "VIPS_ANGLE45_315", "315"},
{VIPS_ANGLE45_LAST, "VIPS_ANGLE45_LAST", "last"},
{0, NULL, NULL}
};
etype = g_enum_register_static( "VipsAngle45", values );
}
return( etype );
}
/* enumerations from "../../libvips/include/vips/arithmetic.h" */ /* enumerations from "../../libvips/include/vips/arithmetic.h" */
GType GType
vips_operation_math_get_type( void ) vips_operation_math_get_type( void )

View File

@ -1029,7 +1029,7 @@ int
vips_check_oddsquare( const char *domain, VipsImage *im ) vips_check_oddsquare( const char *domain, VipsImage *im )
{ {
if( im->Xsize != im->Ysize || if( im->Xsize != im->Ysize ||
im->Xsize % 2 != 0 ) { im->Xsize % 2 == 0 ) {
vips_error( domain, vips_error( domain,
"%s", _( "images must be odd and square" ) ); "%s", _( "images must be odd and square" ) );
return( -1 ); return( -1 );

View File

@ -2358,7 +2358,7 @@ int
vips__image_wio_output( VipsImage *image ) vips__image_wio_output( VipsImage *image )
{ {
#ifdef DEBUG_IO #ifdef DEBUG_IO
printf( "vips_image_wio_output: WIO output for %s\n", printf( "vips__image_wio_output: WIO output for %s\n",
image->filename ); image->filename );
#endif/*DEBUG_IO*/ #endif/*DEBUG_IO*/
@ -2367,7 +2367,7 @@ vips__image_wio_output( VipsImage *image )
/* Make sure nothing is attached. /* Make sure nothing is attached.
*/ */
if( image->generate_fn ) { if( image->generate_fn ) {
vips_error( "vips_image_wio_output", vips_error( "vips__image_wio_output",
"%s", _( "image already written" ) ); "%s", _( "image already written" ) );
return( -1 ); return( -1 );
} }
@ -2391,7 +2391,7 @@ vips__image_wio_output( VipsImage *image )
break; break;
default: default:
vips_error( "vips_image_wio_output", vips_error( "vips__image_wio_output",
"%s", _( "image not writeable" ) ); "%s", _( "image not writeable" ) );
return( -1 ); return( -1 );
} }

View File

@ -26,10 +26,10 @@ bin_SCRIPTS = \
batch_image_convert \ batch_image_convert \
batch_rubber_sheet \ batch_rubber_sheet \
batch_crop \ batch_crop \
vips-7.36 vips-7.37
EXTRA_DIST = \ EXTRA_DIST = \
vips-7.36 \ vips-7.37 \
light_correct.in \ light_correct.in \
shrink_width.in \ shrink_width.in \
batch_image_convert.in \ batch_image_convert.in \