make a "create" package

the old "other" package, plus move some of conversion in there
This commit is contained in:
John Cupitt 2013-06-13 10:12:22 +01:00
parent 84f3fa5b19
commit 4436e370c7
24 changed files with 260 additions and 62 deletions

View File

@ -715,7 +715,7 @@ AC_OUTPUT([
libvips/iofuncs/Makefile
libvips/morphology/Makefile
libvips/mosaicing/Makefile
libvips/other/Makefile
libvips/create/Makefile
libvips/resample/Makefile
libvips/video/Makefile
libvipsCC/include/Makefile

View File

@ -44,7 +44,7 @@
<xi:include href="xml/mask.xml"/>
<xi:include href="xml/morphology.xml"/>
<xi:include href="xml/mosaicing.xml"/>
<xi:include href="xml/other.xml"/>
<xi:include href="xml/create.xml"/>
<xi:include href="xml/resample.xml"/>
<xi:include href="xml/video.xml"/>
</chapter>

View File

@ -25,7 +25,7 @@ SUBDIRS = \
iofuncs \
morphology \
mosaicing \
other \
create \
video \
.
@ -58,7 +58,7 @@ libvips_la_LIBADD = \
iofuncs/libiofuncs.la \
morphology/libmorphology.la \
mosaicing/libmosaicing.la \
other/libother.la \
create/libcreate.la \
video/libvideo.la \
@VIPS_LIBS@

View File

@ -16,13 +16,11 @@ libconversion_la_SOURCES = \
replicate.c \
cast.c \
bandjoin.c \
black.c \
recomb.c \
bandmean.c \
bandbool.c \
bandary.h \
bandary.c \
gaussnoise.c \
rot.c \
ifthenelse.c \
im_falsecolour.c \
@ -31,8 +29,6 @@ libconversion_la_SOURCES = \
scale.c \
wrap.c \
subsample.c \
text.c \
xyz.c \
zoom.c
AM_CPPFLAGS = -I${top_srcdir}/libvips/include @VIPS_CFLAGS@ @VIPS_INCLUDES@

View File

@ -1,10 +1,7 @@
/* base class for all conversion operations
*
* properties:
* - unary, binary or binary with one arg a constant
* - cast binary args to match
* - not point-to-point
* - format, bands etc. can all change
* - single output image
*/
/*

View File

@ -112,7 +112,7 @@ vips_wrap_class_init( VipsWrapClass *class )
gobject_class->get_property = vips_object_get_property;
vobject_class->nickname = "wrap";
vobject_class->description = _( "wrap an image to uchar" );
vobject_class->description = _( "wrap image origin" );
vobject_class->build = vips_wrap_build;
VIPS_ARG_IMAGE( class, "in", 1,

View File

@ -1,6 +1,11 @@
noinst_LTLIBRARIES = libother.la
noinst_LTLIBRARIES = libcreate.la
libother_la_SOURCES = \
libcreate_la_SOURCES = \
create.c \
xyz.c \
black.c \
text.c \
gaussnoise.c \
im_benchmark.c \
im_eye.c \
im_grey.c \

View File

@ -61,10 +61,10 @@
#include <vips/internal.h>
#include <vips/debug.h>
#include "conversion.h"
#include "create.h"
typedef struct _VipsBlack {
VipsConversion parent_instance;
VipsCreate parent_instance;
int width;
int height;
@ -72,9 +72,9 @@ typedef struct _VipsBlack {
} VipsBlack;
typedef VipsConversionClass VipsBlackClass;
typedef VipsCreateClass VipsBlackClass;
G_DEFINE_TYPE( VipsBlack, vips_black, VIPS_TYPE_CONVERSION );
G_DEFINE_TYPE( VipsBlack, vips_black, VIPS_TYPE_CREATE );
static int
vips_black_gen( VipsRegion *or, void *seq, void *a, void *b,
@ -88,22 +88,22 @@ vips_black_gen( VipsRegion *or, void *seq, void *a, void *b,
static int
vips_black_build( VipsObject *object )
{
VipsConversion *conversion = VIPS_CONVERSION( object );
VipsCreate *create = VIPS_CREATE( object );
VipsBlack *black = (VipsBlack *) object;
if( VIPS_OBJECT_CLASS( vips_black_parent_class )->build( object ) )
return( -1 );
vips_image_init_fields( conversion->out,
vips_image_init_fields( create->out,
black->width, black->height, black->bands,
VIPS_FORMAT_UCHAR, VIPS_CODING_NONE,
black->bands == 1 ?
VIPS_INTERPRETATION_B_W : VIPS_INTERPRETATION_MULTIBAND,
1.0, 1.0 );
vips_demand_hint( conversion->out,
vips_demand_hint( create->out,
VIPS_DEMAND_STYLE_ANY, NULL );
if( vips_image_generate( conversion->out,
if( vips_image_generate( create->out,
NULL, vips_black_gen, NULL, NULL, NULL ) )
return( -1 );

115
libvips/create/create.c Normal file
View File

@ -0,0 +1,115 @@
/* base class for all create operations
*
* properties:
* - single output image we build
*/
/*
Copyright (C) 1991-2005 The National Gallery
This library 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.1 of the License, or (at your option) any later version.
This library 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 library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
/*
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
*/
/*
#define DEBUG
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vips/vips.h>
#include <vips/internal.h>
#include "create.h"
G_DEFINE_ABSTRACT_TYPE( VipsCreate, vips_create, VIPS_TYPE_OPERATION );
static int
vips_create_build( VipsObject *object )
{
VipsCreate *create = VIPS_CREATE( object );
#ifdef DEBUG
printf( "vips_create_build: " );
vips_object_print_name( object );
printf( "\n" );
#endif /*DEBUG*/
g_object_set( create, "out", vips_image_new(), NULL );
if( VIPS_OBJECT_CLASS( vips_create_parent_class )->build( object ) )
return( -1 );
return( 0 );
}
static void
vips_create_class_init( VipsCreateClass *class )
{
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class );
gobject_class->set_property = vips_object_set_property;
gobject_class->get_property = vips_object_get_property;
vobject_class->nickname = "create";
vobject_class->description = _( "create operations" );
vobject_class->build = vips_create_build;
VIPS_ARG_IMAGE( class, "out", 1,
_( "Output" ),
_( "Output image" ),
VIPS_ARGUMENT_REQUIRED_OUTPUT,
G_STRUCT_OFFSET( VipsCreate, out ) );
}
static void
vips_create_init( VipsCreate *create )
{
}
void
vips_create_operation_init( void )
{
extern GType vips_black_get_type( void );
extern GType vips_gaussnoise_get_type( void );
#ifdef HAVE_PANGOFT2
extern GType vips_text_get_type( void );
#endif /*HAVE_PANGOFT2*/
extern GType vips_xyz_get_type( void );
vips_black_get_type();
vips_gaussnoise_get_type();
#ifdef HAVE_PANGOFT2
vips_text_get_type();
#endif /*HAVE_PANGOFT2*/
vips_xyz_get_type();
}

79
libvips/create/create.h Normal file
View File

@ -0,0 +1,79 @@
/* base class for all create operations
*/
/*
Copyright (C) 1991-2005 The National Gallery
This library 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.1 of the License, or (at your option) any later version.
This library 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 library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
/*
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
*/
/* We don't want to get confused with the create.h in include, put an
* extra _ in there.
*/
#ifndef VIPS__CREATE_H
#define VIPS__CREATE_H
#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus*/
#define VIPS_TYPE_CREATE (vips_create_get_type())
#define VIPS_CREATE( obj ) \
(G_TYPE_CHECK_INSTANCE_CAST( (obj), \
VIPS_TYPE_CREATE, VipsCreate ))
#define VIPS_CREATE_CLASS( klass ) \
(G_TYPE_CHECK_CLASS_CAST( (klass), \
VIPS_TYPE_CREATE, VipsCreateClass))
#define VIPS_IS_CREATE( obj ) \
(G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_CREATE ))
#define VIPS_IS_CREATE_CLASS( klass ) \
(G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_CREATE ))
#define VIPS_CREATE_GET_CLASS( obj ) \
(G_TYPE_INSTANCE_GET_CLASS( (obj), \
VIPS_TYPE_CREATE, VipsCreateClass ))
typedef struct _VipsCreate {
VipsOperation parent_instance;
/* All have an output image.
*/
VipsImage *out;
} VipsCreate;
typedef struct _VipsCreateClass {
VipsOperationClass parent_class;
} VipsCreateClass;
GType vips_create_get_type( void );
#ifdef __cplusplus
}
#endif /*__cplusplus*/
#endif /*VIPS__CREATE_H*/

View File

@ -59,10 +59,10 @@
#include <vips/vips.h>
#include "conversion.h"
#include "create.h"
typedef struct _VipsGaussnoise {
VipsConversion parent_instance;
VipsCreate parent_instance;
int width;
int height;
@ -71,9 +71,9 @@ typedef struct _VipsGaussnoise {
} VipsGaussnoise;
typedef VipsConversionClass VipsGaussnoiseClass;
typedef VipsCreateClass VipsGaussnoiseClass;
G_DEFINE_TYPE( VipsGaussnoise, vips_gaussnoise, VIPS_TYPE_CONVERSION );
G_DEFINE_TYPE( VipsGaussnoise, vips_gaussnoise, VIPS_TYPE_CREATE );
/* Make a random number in 0 - 1. Prefer random().
*/
@ -121,20 +121,20 @@ vips_gaussnoise_gen( VipsRegion *or, void *seq, void *a, void *b,
static int
vips_gaussnoise_build( VipsObject *object )
{
VipsConversion *conversion = VIPS_CONVERSION( object );
VipsCreate *create = VIPS_CREATE( object );
VipsGaussnoise *gaussnoise = (VipsGaussnoise *) object;
if( VIPS_OBJECT_CLASS( vips_gaussnoise_parent_class )->build( object ) )
return( -1 );
vips_image_init_fields( conversion->out,
vips_image_init_fields( create->out,
gaussnoise->width, gaussnoise->height, 1,
VIPS_FORMAT_FLOAT, VIPS_CODING_NONE,
VIPS_INTERPRETATION_B_W, 1.0, 1.0 );
vips_demand_hint( conversion->out,
vips_demand_hint( create->out,
VIPS_DEMAND_STYLE_ANY, NULL );
if( vips_image_generate( conversion->out,
if( vips_image_generate( create->out,
NULL, vips_gaussnoise_gen, NULL, gaussnoise, NULL ) )
return( -1 );

View File

@ -56,10 +56,10 @@
#include <pango/pango.h>
#include <pango/pangoft2.h>
#include "conversion.h"
#include "create.h"
typedef struct _VipsText {
VipsConversion parent_instance;
VipsCreate parent_instance;
char *text;
char *font;
@ -73,9 +73,9 @@ typedef struct _VipsText {
} VipsText;
typedef VipsConversionClass VipsTextClass;
typedef VipsCreateClass VipsTextClass;
G_DEFINE_TYPE( VipsText, vips_text, VIPS_TYPE_CONVERSION );
G_DEFINE_TYPE( VipsText, vips_text, VIPS_TYPE_CREATE );
/* Just have one of these and reuse it.
*
@ -146,7 +146,7 @@ static int
vips_text_build( VipsObject *object )
{
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object );
VipsConversion *conversion = VIPS_CONVERSION( object );
VipsCreate *create = VIPS_CREATE( object );
VipsText *text = (VipsText *) object;
PangoRectangle logical_rect;
@ -229,15 +229,15 @@ vips_text_build( VipsObject *object )
g_mutex_unlock( vips_text_lock );
vips_image_init_fields( conversion->out,
vips_image_init_fields( create->out,
text->bitmap.width, text->bitmap.rows, 1,
VIPS_FORMAT_UCHAR, VIPS_CODING_NONE, VIPS_INTERPRETATION_B_W,
1.0, 1.0 );
vips_demand_hint( conversion->out,
vips_demand_hint( create->out,
VIPS_DEMAND_STYLE_ANY, NULL );
for( y = 0; y < text->bitmap.rows; y++ )
if( vips_image_write_line( conversion->out, y,
if( vips_image_write_line( create->out, y,
(VipsPel *) text->bitmap.buffer +
y * text->bitmap.pitch ) )
return( -1 );

View File

@ -52,10 +52,10 @@
#include <vips/internal.h>
#include <vips/debug.h>
#include "conversion.h"
#include "create.h"
typedef struct _VipsXyz {
VipsConversion parent_instance;
VipsCreate parent_instance;
int width;
int height;
@ -67,9 +67,9 @@ typedef struct _VipsXyz {
} VipsXyz;
typedef VipsConversionClass VipsXyzClass;
typedef VipsCreateClass VipsXyzClass;
G_DEFINE_TYPE( VipsXyz, vips_xyz, VIPS_TYPE_CONVERSION );
G_DEFINE_TYPE( VipsXyz, vips_xyz, VIPS_TYPE_CREATE );
static int
vips_xyz_gen( VipsRegion *or, void *seq, void *a, void *b,
@ -122,7 +122,7 @@ static int
vips_xyz_build( VipsObject *object )
{
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object );
VipsConversion *conversion = VIPS_CONVERSION( object );
VipsCreate *create = VIPS_CREATE( object );
VipsXyz *xyz = (VipsXyz *) object;
double d;
@ -158,15 +158,15 @@ vips_xyz_build( VipsObject *object )
}
ysize = d;
vips_image_init_fields( conversion->out,
vips_image_init_fields( create->out,
xyz->width, ysize, xyz->dimensions,
VIPS_FORMAT_UINT, VIPS_CODING_NONE,
VIPS_INTERPRETATION_MULTIBAND,
1.0, 1.0 );
vips_demand_hint( conversion->out,
vips_demand_hint( create->out,
VIPS_DEMAND_STYLE_ANY, NULL );
if( vips_image_generate( conversion->out,
if( vips_image_generate( create->out,
NULL, vips_xyz_gen, NULL, xyz, NULL ) )
return( -1 );

View File

@ -27,7 +27,7 @@ pkginclude_HEADERS = \
memory.h \
morphology.h \
mosaicing.h \
other.h \
create.h \
video.h \
cimg_funcs.h \
object.h \

View File

@ -250,15 +250,6 @@ int vips_bandeor( VipsImage *in, VipsImage **out, ... )
int vips_recomb( VipsImage *in, VipsImage **out, VipsImage *m, ... )
__attribute__((sentinel));
int vips_black( VipsImage **out, int width, int height, ... )
__attribute__((sentinel));
int vips_xyz( VipsImage **out, int width, int height, ... )
__attribute__((sentinel));
int vips_text( VipsImage **out, const char *text, ... )
__attribute__((sentinel));
int vips_gaussnoise( VipsImage **out, int width, int height, ... )
__attribute__((sentinel));
int vips_ifthenelse( VipsImage *cond, VipsImage *in1, VipsImage *in2,
VipsImage **out, ... )
__attribute__((sentinel));

View File

@ -1,4 +1,4 @@
/* other.h
/* create.h
*
* 20/9/09
* - from proto.h
@ -31,13 +31,27 @@
*/
#ifndef IM_OTHER_H
#define IM_OTHER_H
#ifndef VIPS_CREATE_H
#define VIPS_CREATE_H
#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus*/
void vips_create_operation_init( void );
int vips_black( VipsImage **out, int width, int height, ... )
__attribute__((sentinel));
int vips_xyz( VipsImage **out, int width, int height, ... )
__attribute__((sentinel));
int vips_text( VipsImage **out, const char *text, ... )
__attribute__((sentinel));
int vips_gaussnoise( VipsImage **out, int width, int height, ... )
__attribute__((sentinel));
int im_grey( VipsImage *out, const int xsize, const int ysize );
int im_fgrey( VipsImage *out, const int xsize, const int ysize );
@ -57,4 +71,4 @@ int im_benchmark2( VipsImage *in, double *out );
}
#endif /*__cplusplus*/
#endif /*IM_OTHER_H*/
#endif /*VIPS_CREATE_H*/

View File

@ -134,7 +134,7 @@ extern "C" {
#include <vips/resample.h>
#include <vips/colour.h>
#include <vips/inplace.h>
#include <vips/other.h>
#include <vips/create.h>
#include <vips/video.h>
#include <vips/cimg_funcs.h>

View File

@ -245,6 +245,7 @@ vips_init( const char *argv0 )
(void) vips_system_get_type();
vips_arithmetic_operation_init();
vips_conversion_operation_init();
vips_create_operation_init();
vips_foreign_operation_init();
vips_resample_operation_init();
vips_colour_operation_init();