move extract_band to bandary
This commit is contained in:
parent
09eeb7e1a3
commit
42e631f4d3
2
TODO
2
TODO
@ -1,5 +1,3 @@
|
|||||||
- move extract_band to bandary
|
|
||||||
|
|
||||||
- get real, get_imag can be arith unary ops
|
- get real, get_imag can be arith unary ops
|
||||||
|
|
||||||
- form complex can be an arith binary op
|
- form complex can be an arith binary op
|
||||||
|
@ -157,12 +157,22 @@ vips_bandmean_buffer( VipsBandary *bandary, PEL *out, PEL **in, int width )
|
|||||||
static int
|
static int
|
||||||
vips_bandmean_build( VipsObject *object )
|
vips_bandmean_build( VipsObject *object )
|
||||||
{
|
{
|
||||||
|
VipsConversion *conversion = VIPS_CONVERSION( object );
|
||||||
VipsBandary *bandary = (VipsBandary *) object;
|
VipsBandary *bandary = (VipsBandary *) object;
|
||||||
VipsBandmean *bandmean = (VipsBandmean *) object;
|
VipsBandmean *bandmean = (VipsBandmean *) object;
|
||||||
|
|
||||||
bandary->out_bands = 1;
|
bandary->out_bands = 1;
|
||||||
|
|
||||||
if( bandmean->in ) {
|
if( bandmean->in ) {
|
||||||
|
if( bandmean->in->Bands == 1 ) {
|
||||||
|
g_object_set( conversion,
|
||||||
|
"out", vips_image_new(),
|
||||||
|
NULL );
|
||||||
|
|
||||||
|
return( vips_image_write( bandmean->in,
|
||||||
|
conversion->out ) );
|
||||||
|
}
|
||||||
|
|
||||||
bandary->n = 1;
|
bandary->n = 1;
|
||||||
bandary->in = &bandmean->in;
|
bandary->in = &bandmean->in;
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,8 @@
|
|||||||
|
|
||||||
#include "conversion.h"
|
#include "conversion.h"
|
||||||
|
|
||||||
|
#include "bandary.h"
|
||||||
|
|
||||||
typedef struct _VipsExtractArea {
|
typedef struct _VipsExtractArea {
|
||||||
VipsConversion parent_instance;
|
VipsConversion parent_instance;
|
||||||
|
|
||||||
@ -262,7 +264,7 @@ vips_extract_area( VipsImage *in, VipsImage **out,
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef struct _VipsExtractBand {
|
typedef struct _VipsExtractBand {
|
||||||
VipsConversion parent_instance;
|
VipsBandary parent_instance;
|
||||||
|
|
||||||
/* The input image.
|
/* The input image.
|
||||||
*/
|
*/
|
||||||
@ -270,76 +272,67 @@ typedef struct _VipsExtractBand {
|
|||||||
|
|
||||||
int band;
|
int band;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
} VipsExtractBand;
|
} VipsExtractBand;
|
||||||
|
|
||||||
typedef VipsConversionClass VipsExtractBandClass;
|
typedef VipsBandaryClass VipsExtractBandClass;
|
||||||
|
|
||||||
G_DEFINE_TYPE( VipsExtractBand, vips_extract_band, VIPS_TYPE_CONVERSION );
|
G_DEFINE_TYPE( VipsExtractBand, vips_extract_band, VIPS_TYPE_BANDARY );
|
||||||
|
|
||||||
static int
|
static void
|
||||||
vips_extract_band_gen( VipsRegion *or, void *seq, void *a, void *b,
|
vips_extract_band_buffer( VipsBandary *bandary, PEL *out, PEL **in, int width )
|
||||||
gboolean *stop )
|
|
||||||
{
|
{
|
||||||
VipsRegion *ir = (VipsRegion *) seq;
|
VipsConversion *conversion = (VipsConversion *) bandary;
|
||||||
VipsExtractBand *extract = (VipsExtractBand *) b;
|
VipsExtractBand *extract = (VipsExtractBand *) bandary;
|
||||||
VipsRect *r = &or->valid;
|
VipsImage *im = bandary->ready[0];
|
||||||
int es = VIPS_IMAGE_SIZEOF_ELEMENT( ir->im );
|
int es = VIPS_IMAGE_SIZEOF_ELEMENT( im );
|
||||||
int ipel = VIPS_IMAGE_SIZEOF_PEL( ir->im );
|
int ips = VIPS_IMAGE_SIZEOF_PEL( im );
|
||||||
int opel = VIPS_IMAGE_SIZEOF_PEL( or->im );
|
const int ops = VIPS_IMAGE_SIZEOF_PEL( conversion->out );
|
||||||
|
|
||||||
char *p, *q;
|
PEL *p, *q;
|
||||||
int x, y, z;
|
int x, z;
|
||||||
|
|
||||||
if( vips_region_prepare( ir, r ) )
|
p = in[0] + extract->band * es;
|
||||||
return( -1 );
|
q = out;
|
||||||
|
for( x = 0; x < width; x++ ) {
|
||||||
for( y = 0; y < r->height; y++ ) {
|
for( z = 0; z < ops; z++ )
|
||||||
p = VIPS_REGION_ADDR( ir, r->left, r->top + y ) +
|
|
||||||
extract->band * es;
|
|
||||||
q = VIPS_REGION_ADDR( or, r->left, r->top + y );
|
|
||||||
|
|
||||||
for( x = 0; x < r->width; x++ ) {
|
|
||||||
for( z = 0; z < opel; z++ )
|
|
||||||
q[z] = p[z];
|
q[z] = p[z];
|
||||||
|
|
||||||
p += ipel;
|
p += ips;
|
||||||
q += opel;
|
q += ops;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return( 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
vips_extract_band_build( VipsObject *object )
|
vips_extract_band_build( VipsObject *object )
|
||||||
{
|
{
|
||||||
VipsConversion *conversion = VIPS_CONVERSION( object );
|
VipsConversion *conversion = VIPS_CONVERSION( object );
|
||||||
|
VipsBandary *bandary = (VipsBandary *) object;
|
||||||
VipsExtractBand *extract = (VipsExtractBand *) object;
|
VipsExtractBand *extract = (VipsExtractBand *) object;
|
||||||
|
|
||||||
if( VIPS_OBJECT_CLASS( vips_extract_band_parent_class )->build( object ) )
|
if( extract->in ) {
|
||||||
return( -1 );
|
|
||||||
|
|
||||||
if( extract->band + extract->n > extract->in->Bands ) {
|
if( extract->band + extract->n > extract->in->Bands ) {
|
||||||
vips_error( "VipsExtractBand", "%s", _( "bad extract band" ) );
|
vips_error( "VipsExtractBand",
|
||||||
|
"%s", _( "bad extract band" ) );
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( vips_image_pio_input( extract->in ) ||
|
if( extract->band == 0 &&
|
||||||
vips_image_pio_output( conversion->out ) ||
|
extract->n == extract->in->Bands ) {
|
||||||
vips_check_coding_known( "VipsExtractBand", extract->in ) )
|
g_object_set( conversion,
|
||||||
return( -1 );
|
"out", vips_image_new(),
|
||||||
|
NULL );
|
||||||
|
|
||||||
if( vips_image_copy_fields( conversion->out, extract->in ) )
|
return( vips_image_write( extract->in,
|
||||||
return( -1 );
|
conversion->out ) );
|
||||||
vips_demand_hint( conversion->out,
|
}
|
||||||
VIPS_DEMAND_STYLE_THINSTRIP, extract->in, NULL );
|
|
||||||
|
|
||||||
conversion->out->Bands = extract->n;
|
bandary->n = 1;
|
||||||
|
bandary->in = &extract->in;
|
||||||
|
bandary->out_bands = extract->n;
|
||||||
|
}
|
||||||
|
|
||||||
if( vips_image_generate( conversion->out,
|
if( VIPS_OBJECT_CLASS( vips_extract_band_parent_class )->
|
||||||
vips_start_one, vips_extract_band_gen, vips_stop_one,
|
build( object ) )
|
||||||
extract->in, extract ) )
|
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
@ -350,6 +343,7 @@ vips_extract_band_class_init( VipsExtractBandClass *class )
|
|||||||
{
|
{
|
||||||
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
|
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
|
||||||
VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class );
|
VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class );
|
||||||
|
VipsBandaryClass *bandary_class = VIPS_BANDARY_CLASS( class );
|
||||||
|
|
||||||
VIPS_DEBUG_MSG( "vips_extract_band_class_init\n" );
|
VIPS_DEBUG_MSG( "vips_extract_band_class_init\n" );
|
||||||
|
|
||||||
@ -360,6 +354,8 @@ vips_extract_band_class_init( VipsExtractBandClass *class )
|
|||||||
vobject_class->description = _( "extract band from an image" );
|
vobject_class->description = _( "extract band from an image" );
|
||||||
vobject_class->build = vips_extract_band_build;
|
vobject_class->build = vips_extract_band_build;
|
||||||
|
|
||||||
|
bandary_class->process_line = vips_extract_band_buffer;
|
||||||
|
|
||||||
VIPS_ARG_IMAGE( class, "in", 0,
|
VIPS_ARG_IMAGE( class, "in", 0,
|
||||||
_( "Input" ),
|
_( "Input" ),
|
||||||
_( "Input image" ),
|
_( "Input image" ),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user