needs testing still
This commit is contained in:
parent
dd07d6ab7d
commit
9ac45f42e3
libvips
220
libvips/conversion/transpose3d.c
Normal file
220
libvips/conversion/transpose3d.c
Normal file
@ -0,0 +1,220 @@
|
||||
/* vips_transpose3d
|
||||
*
|
||||
* 30/4/18
|
||||
* - from grid.c as a class
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 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 <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <vips/vips.h>
|
||||
|
||||
#include "pconversion.h"
|
||||
|
||||
typedef struct _VipsTranspose3d {
|
||||
VipsConversion parent_instance;
|
||||
|
||||
VipsImage *in;
|
||||
|
||||
int tile_height;
|
||||
|
||||
} VipsTranspose3d;
|
||||
|
||||
typedef VipsConversionClass VipsTranspose3dClass;
|
||||
|
||||
G_DEFINE_TYPE( VipsTranspose3d, vips_transpose3d, VIPS_TYPE_CONVERSION );
|
||||
|
||||
static int
|
||||
vips_transpose3d_gen( VipsRegion *or, void *vseq, void *a, void *b,
|
||||
gboolean *stop )
|
||||
{
|
||||
VipsRegion *ir = (VipsRegion *) vseq;
|
||||
VipsImage *in = (VipsImage *) a;
|
||||
VipsTranspose3d *transpose3d = (VipsTranspose3d *) b;
|
||||
VipsRect *r = &or->valid;
|
||||
|
||||
int output_page_height = in->Ysize / transpose3d->page_height;
|
||||
|
||||
int x, y;
|
||||
VipsRect tile;
|
||||
|
||||
tile = *r;
|
||||
tile.height = 1;
|
||||
|
||||
for( y = 0; y < r->height; y++ ) {
|
||||
/* y in output.
|
||||
*/
|
||||
int yo = r->top + y;
|
||||
|
||||
/* On output page.
|
||||
*/
|
||||
int yop = yo / output_page_height;
|
||||
|
||||
/* Line on output page.
|
||||
*/
|
||||
int yol = yo % output_page_height;
|
||||
|
||||
/* y of input page.
|
||||
*/
|
||||
int yip = yol * transpose3d->page_height;
|
||||
|
||||
/* y of input line.
|
||||
*/
|
||||
yi = yip + yop;
|
||||
|
||||
tile.top = yo;
|
||||
|
||||
/* Render into or.
|
||||
*/
|
||||
if( vips_region_prepare_to( ir, or, &tile, tile.left, yi )
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static int
|
||||
vips_transpose3d_build( VipsObject *object )
|
||||
{
|
||||
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object );
|
||||
VipsConversion *conversion = VIPS_CONVERSION( object );
|
||||
VipsTranspose3d *transpose3d = (VipsTranspose3d *) object;
|
||||
|
||||
VipsImage *in;
|
||||
|
||||
if( VIPS_OBJECT_CLASS( vips_transpose3d_parent_class )->
|
||||
build( object ) )
|
||||
return( -1 );
|
||||
|
||||
in = transpose3d->in;
|
||||
|
||||
if( vips_check_coding_known( class->nickname, in ) ||
|
||||
vips_image_pio_input( in ) )
|
||||
return( -1 );
|
||||
|
||||
if( !vips_object_argument_isset( object, "page_height" ) ) {
|
||||
if( vips_image_get_int( in,
|
||||
VIPS_META_PAGE_HEIGHT, &transpose3d->page_height ) )
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
if( transpose3d->page_height <= 0 ||
|
||||
in->Ysize % transpose3d->page_height != 0 ) {
|
||||
vips_error( class->nickname, "%s", _( "bad page_height" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
if( vips_image_pipelinev( conversion->out,
|
||||
VIPS_DEMAND_STYLE_SMALLTILE, in, NULL ) )
|
||||
return( -1 );
|
||||
vips_image_set_int( conversion->out,
|
||||
VIPS_META_PAGE_HEIGHT, in->Ysize / transpose3d->page_height );
|
||||
|
||||
if( vips_image_generate( conversion->out,
|
||||
vips_start_one, vips_transpose3d_gen, vips_stop_one,
|
||||
in, transpose3d ) )
|
||||
return( -1 );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static void
|
||||
vips_transpose3d_class_init( VipsTranspose3dClass *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 = "transpose3d";
|
||||
vobject_class->description = _( "transpose3d an image" );
|
||||
vobject_class->build = vips_transpose3d_build;
|
||||
|
||||
VIPS_ARG_IMAGE( class, "in", 1,
|
||||
_( "Input" ),
|
||||
_( "Input image" ),
|
||||
VIPS_ARGUMENT_REQUIRED_INPUT,
|
||||
G_STRUCT_OFFSET( VipsTranspose3d, in ) );
|
||||
|
||||
VIPS_ARG_INT( class, "page_height", 3,
|
||||
_( "Page height" ),
|
||||
_( "Height of each input page" ),
|
||||
VIPS_ARGUMENT_OPTIONAL_INPUT,
|
||||
G_STRUCT_OFFSET( VipsTranspose3d, page_height ),
|
||||
0, 10000000, 0 );
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
vips_transpose3d_init( VipsTranspose3d *transpose3d )
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* vips_transpose3d: (method)
|
||||
* @in: input image
|
||||
* @out: (out): output image
|
||||
* @...: %NULL-terminated list of optional named arguments
|
||||
*
|
||||
* Optional arguments:
|
||||
*
|
||||
* @page_height: %gint, size of each input page
|
||||
*
|
||||
* Transpose a volumetric image.
|
||||
*
|
||||
* Volumetric images are very tall, thin images, with the metadata item
|
||||
* `page-height` set to the height of each sub-image.
|
||||
*
|
||||
* This operation swaps two dimensions around so that one row in each input
|
||||
* page becomes one row in a single output page.
|
||||
*
|
||||
* See also: vips_transpose3d().
|
||||
*
|
||||
* Returns: 0 on success, -1 on error
|
||||
*/
|
||||
int
|
||||
vips_transpose3d( VipsImage *in, VipsImage **out, ... )
|
||||
{
|
||||
va_list ap;
|
||||
int result;
|
||||
|
||||
va_start( ap, down );
|
||||
result = vips_call_split( "transpose3d", ap, in, out );
|
||||
va_end( ap );
|
||||
|
||||
return( result );
|
||||
}
|
@ -1,16 +1,58 @@
|
||||
|
||||
/* Generated data (by glib-mkenums) */
|
||||
/* This file is generated by glib-mkenums, do not modify it. This code is licensed under the same license as the containing project. Note that it links to GLib, so must comply with the LGPL linking clauses. */
|
||||
|
||||
#ifndef VIPS_ENUM_TYPES_H
|
||||
#define VIPS_ENUM_TYPES_H
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* enumerations from "../../../libvips/include/vips/resample.h" */
|
||||
GType vips_kernel_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_KERNEL (vips_kernel_get_type())
|
||||
GType vips_size_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_SIZE (vips_size_get_type())
|
||||
/* enumerations from "../../../libvips/include/vips/arithmetic.h" */
|
||||
GType vips_operation_math_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_OPERATION_MATH (vips_operation_math_get_type())
|
||||
GType vips_operation_math2_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_OPERATION_MATH2 (vips_operation_math2_get_type())
|
||||
GType vips_operation_round_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_OPERATION_ROUND (vips_operation_round_get_type())
|
||||
GType vips_operation_relational_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_OPERATION_RELATIONAL (vips_operation_relational_get_type())
|
||||
GType vips_operation_boolean_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_OPERATION_BOOLEAN (vips_operation_boolean_get_type())
|
||||
GType vips_operation_complex_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_OPERATION_COMPLEX (vips_operation_complex_get_type())
|
||||
GType vips_operation_complex2_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_OPERATION_COMPLEX2 (vips_operation_complex2_get_type())
|
||||
GType vips_operation_complexget_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_OPERATION_COMPLEXGET (vips_operation_complexget_get_type())
|
||||
/* enumerations from "../../../libvips/include/vips/basic.h" */
|
||||
GType vips_precision_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_PRECISION (vips_precision_get_type())
|
||||
/* enumerations from "../../../libvips/include/vips/colour.h" */
|
||||
GType vips_intent_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_INTENT (vips_intent_get_type())
|
||||
GType vips_pcs_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_PCS (vips_pcs_get_type())
|
||||
/* enumerations from "../../../libvips/include/vips/conversion.h" */
|
||||
GType vips_extend_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_EXTEND (vips_extend_get_type())
|
||||
GType vips_compass_direction_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_COMPASS_DIRECTION (vips_compass_direction_get_type())
|
||||
GType vips_direction_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_DIRECTION (vips_direction_get_type())
|
||||
GType vips_align_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_ALIGN (vips_align_get_type())
|
||||
GType vips_angle_get_type (void) G_GNUC_CONST;
|
||||
#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())
|
||||
GType vips_interesting_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_INTERESTING (vips_interesting_get_type())
|
||||
GType vips_blend_mode_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_BLEND_MODE (vips_blend_mode_get_type())
|
||||
/* enumerations from "../../../libvips/include/vips/convolution.h" */
|
||||
GType vips_combine_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_COMBINE (vips_combine_get_type())
|
||||
/* enumerations from "../../../libvips/include/vips/draw.h" */
|
||||
GType vips_combine_mode_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_COMBINE_MODE (vips_combine_mode_get_type())
|
||||
/* enumerations from "../../../libvips/include/vips/foreign.h" */
|
||||
GType vips_foreign_flags_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_FOREIGN_FLAGS (vips_foreign_flags_get_type())
|
||||
@ -32,43 +74,6 @@ GType vips_foreign_dz_depth_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_FOREIGN_DZ_DEPTH (vips_foreign_dz_depth_get_type())
|
||||
GType vips_foreign_dz_container_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_FOREIGN_DZ_CONTAINER (vips_foreign_dz_container_get_type())
|
||||
/* enumerations from "../../../libvips/include/vips/arithmetic.h" */
|
||||
GType vips_operation_math_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_OPERATION_MATH (vips_operation_math_get_type())
|
||||
GType vips_operation_math2_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_OPERATION_MATH2 (vips_operation_math2_get_type())
|
||||
GType vips_operation_round_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_OPERATION_ROUND (vips_operation_round_get_type())
|
||||
GType vips_operation_relational_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_OPERATION_RELATIONAL (vips_operation_relational_get_type())
|
||||
GType vips_operation_boolean_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_OPERATION_BOOLEAN (vips_operation_boolean_get_type())
|
||||
GType vips_operation_complex_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_OPERATION_COMPLEX (vips_operation_complex_get_type())
|
||||
GType vips_operation_complex2_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_OPERATION_COMPLEX2 (vips_operation_complex2_get_type())
|
||||
GType vips_operation_complexget_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_OPERATION_COMPLEXGET (vips_operation_complexget_get_type())
|
||||
/* enumerations from "../../../libvips/include/vips/conversion.h" */
|
||||
GType vips_extend_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_EXTEND (vips_extend_get_type())
|
||||
GType vips_compass_direction_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_COMPASS_DIRECTION (vips_compass_direction_get_type())
|
||||
GType vips_direction_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_DIRECTION (vips_direction_get_type())
|
||||
GType vips_align_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_ALIGN (vips_align_get_type())
|
||||
GType vips_angle_get_type (void) G_GNUC_CONST;
|
||||
#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())
|
||||
GType vips_interesting_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_INTERESTING (vips_interesting_get_type())
|
||||
GType vips_blend_mode_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_BLEND_MODE (vips_blend_mode_get_type())
|
||||
/* enumerations from "../../../libvips/include/vips/util.h" */
|
||||
GType vips_token_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_TOKEN (vips_token_get_type())
|
||||
/* enumerations from "../../../libvips/include/vips/image.h" */
|
||||
GType vips_demand_style_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_DEMAND_STYLE (vips_demand_style_get_type())
|
||||
@ -82,29 +87,23 @@ GType vips_coding_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_CODING (vips_coding_get_type())
|
||||
GType vips_access_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_ACCESS (vips_access_get_type())
|
||||
/* enumerations from "../../../libvips/include/vips/colour.h" */
|
||||
GType vips_intent_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_INTENT (vips_intent_get_type())
|
||||
GType vips_pcs_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_PCS (vips_pcs_get_type())
|
||||
/* enumerations from "../../../libvips/include/vips/operation.h" */
|
||||
GType vips_operation_flags_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_OPERATION_FLAGS (vips_operation_flags_get_type())
|
||||
/* enumerations from "../../../libvips/include/vips/convolution.h" */
|
||||
GType vips_combine_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_COMBINE (vips_combine_get_type())
|
||||
/* enumerations from "../../../libvips/include/vips/morphology.h" */
|
||||
GType vips_operation_morphology_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_OPERATION_MORPHOLOGY (vips_operation_morphology_get_type())
|
||||
/* enumerations from "../../../libvips/include/vips/draw.h" */
|
||||
GType vips_combine_mode_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_COMBINE_MODE (vips_combine_mode_get_type())
|
||||
/* enumerations from "../../../libvips/include/vips/basic.h" */
|
||||
GType vips_precision_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_PRECISION (vips_precision_get_type())
|
||||
/* enumerations from "../../../libvips/include/vips/object.h" */
|
||||
GType vips_argument_flags_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_ARGUMENT_FLAGS (vips_argument_flags_get_type())
|
||||
/* enumerations from "../../../libvips/include/vips/operation.h" */
|
||||
GType vips_operation_flags_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_OPERATION_FLAGS (vips_operation_flags_get_type())
|
||||
/* enumerations from "../../../libvips/include/vips/resample.h" */
|
||||
GType vips_kernel_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_KERNEL (vips_kernel_get_type())
|
||||
GType vips_size_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_SIZE (vips_size_get_type())
|
||||
/* enumerations from "../../../libvips/include/vips/util.h" */
|
||||
GType vips_token_get_type (void) G_GNUC_CONST;
|
||||
#define VIPS_TYPE_TOKEN (vips_token_get_type())
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*VIPS_ENUM_TYPES_H*/
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user