support uchar and ushort gmic images
This commit is contained in:
parent
b8c47eea9f
commit
ea2d6e5283
@ -13201,11 +13201,21 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
// Explicitely instanciate constructor for float-valued images.
|
// Explicitely instanciate constructor for other image types
|
||||||
template gmic::gmic(const char *const commands_line,
|
template gmic::gmic(const char *const commands_line,
|
||||||
gmic_list<float>& images, gmic_list<char>& images_names,
|
gmic_list<float>& images, gmic_list<char>& images_names,
|
||||||
const char *const custom_commands=0,
|
const char *const custom_commands=0,
|
||||||
const bool include_default_commands=true,
|
const bool include_default_commands=true,
|
||||||
float *const p_progress=0, int *const p_cancel=0);
|
float *const p_progress=0, int *const p_cancel=0);
|
||||||
|
template gmic::gmic(const char *const commands_line,
|
||||||
|
gmic_list<unsigned char>& images, gmic_list<char>& images_names,
|
||||||
|
const char *const custom_commands=0,
|
||||||
|
const bool include_default_commands=true,
|
||||||
|
float *const p_progress=0, int *const p_cancel=0);
|
||||||
|
template gmic::gmic(const char *const commands_line,
|
||||||
|
gmic_list<unsigned short>& images, gmic_list<char>& images_names,
|
||||||
|
const char *const custom_commands=0,
|
||||||
|
const bool include_default_commands=true,
|
||||||
|
float *const p_progress=0, int *const p_cancel=0);
|
||||||
#endif // #ifdef gmic_main
|
#endif // #ifdef gmic_main
|
||||||
#endif // #ifdef cimg_plugin
|
#endif // #ifdef cimg_plugin
|
||||||
|
@ -60,7 +60,6 @@ typedef struct _VipsGMic {
|
|||||||
|
|
||||||
typedef VipsOperationClass VipsGMicClass;
|
typedef VipsOperationClass VipsGMicClass;
|
||||||
|
|
||||||
|
|
||||||
#define VIPS_TYPE_GMIC (vips_gmic_get_type())
|
#define VIPS_TYPE_GMIC (vips_gmic_get_type())
|
||||||
#define VIPS_GMIC( obj ) \
|
#define VIPS_GMIC( obj ) \
|
||||||
(G_TYPE_CHECK_INSTANCE_CAST( (obj), VIPS_TYPE_GMIC, VipsGMic ))
|
(G_TYPE_CHECK_INSTANCE_CAST( (obj), VIPS_TYPE_GMIC, VipsGMic ))
|
||||||
@ -78,7 +77,7 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
gmic_get_tile_border( VipsGMic *vipsgmic )
|
vips_gmic_get_tile_border( VipsGMic *vipsgmic )
|
||||||
{
|
{
|
||||||
return( vipsgmic->padding );
|
return( vipsgmic->padding );
|
||||||
}
|
}
|
||||||
@ -87,14 +86,13 @@ gmic_get_tile_border( VipsGMic *vipsgmic )
|
|||||||
((*(IMG))( (guint) (X), (guint) (Y), (guint) (Z), 0 ))
|
((*(IMG))( (guint) (X), (guint) (Y), (guint) (Z), 0 ))
|
||||||
|
|
||||||
// copy part of a vips region into a cimg
|
// copy part of a vips region into a cimg
|
||||||
static void
|
template<typename T> static void
|
||||||
vips_to_gmic( VipsRegion *in, VipsRect *area, CImg<float> *img )
|
vips_to_gmic( VipsRegion *in, VipsRect *area, CImg<T> *img )
|
||||||
{
|
{
|
||||||
VipsImage *im = in->im;
|
VipsImage *im = in->im;
|
||||||
|
|
||||||
for( int y = 0; y < area->height; y++ ) {
|
for( int y = 0; y < area->height; y++ ) {
|
||||||
float *p = (float *)
|
T *p = (T *) VIPS_REGION_ADDR( in, area->left, area->top + y );
|
||||||
VIPS_REGION_ADDR( in, area->left, area->top + y );
|
|
||||||
|
|
||||||
for( int x = 0; x < area->width; x++ ) {
|
for( int x = 0; x < area->width; x++ ) {
|
||||||
for( int z = 0; z < im->Bands; z++ )
|
for( int z = 0; z < im->Bands; z++ )
|
||||||
@ -107,8 +105,8 @@ vips_to_gmic( VipsRegion *in, VipsRect *area, CImg<float> *img )
|
|||||||
|
|
||||||
// write a CImg to a vips region
|
// write a CImg to a vips region
|
||||||
// fill out->valid, img has pixels in img_rect
|
// fill out->valid, img has pixels in img_rect
|
||||||
static void
|
template<typename T> static void
|
||||||
gmic_to_vips( gmic_image<float> *img, VipsRect *img_rect, VipsRegion *out )
|
vips_from_gmic( gmic_image<T> *img, VipsRect *img_rect, VipsRegion *out )
|
||||||
{
|
{
|
||||||
VipsImage *im = out->im;
|
VipsImage *im = out->im;
|
||||||
VipsRect *valid = &out->valid;
|
VipsRect *valid = &out->valid;
|
||||||
@ -119,26 +117,26 @@ gmic_to_vips( gmic_image<float> *img, VipsRect *img_rect, VipsRegion *out )
|
|||||||
int y_off = valid->top - img_rect->top;
|
int y_off = valid->top - img_rect->top;
|
||||||
|
|
||||||
for( int y = 0; y < valid->height; y++ ) {
|
for( int y = 0; y < valid->height; y++ ) {
|
||||||
float *p = (float *) \
|
T *p = (T *) \
|
||||||
VIPS_REGION_ADDR( out, valid->left, valid->top + y );
|
VIPS_REGION_ADDR( out, valid->left, valid->top + y );
|
||||||
|
|
||||||
for( int x = 0; x < valid->width; x++ ) {
|
for( int x = 0; x < valid->width; x++ ) {
|
||||||
for( int z = 0; z < im->Bands; z++ )
|
for( int z = 0; z < im->Bands; z++ )
|
||||||
p[z] = (float)
|
p[z] = INDEX( img, x + x_off, y + y_off, z );
|
||||||
INDEX( img, x + x_off, y + y_off, z );
|
|
||||||
|
|
||||||
p += im->Bands;
|
p += im->Bands;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
template<typename T> static int
|
||||||
gmic_gen( VipsRegion *oreg, void *seq, void *a, void *b, gboolean *stop )
|
vips_gmic_gen_template( VipsRegion *oreg,
|
||||||
|
void *seq, void *a, void *b, gboolean *stop )
|
||||||
{
|
{
|
||||||
VipsRegion **ir = (VipsRegion **) seq;
|
VipsRegion **ir = (VipsRegion **) seq;
|
||||||
VipsGMic *vipsgmic = (VipsGMic *) b;
|
VipsGMic *vipsgmic = (VipsGMic *) b;
|
||||||
int ninput = VIPS_AREA( vipsgmic->in )->n;
|
int ninput = VIPS_AREA( vipsgmic->in )->n;
|
||||||
const int tile_border = gmic_get_tile_border( vipsgmic );
|
const int tile_border = vips_gmic_get_tile_border( vipsgmic );
|
||||||
const VipsRect *r = &oreg->valid;
|
const VipsRect *r = &oreg->valid;
|
||||||
|
|
||||||
VipsRect need;
|
VipsRect need;
|
||||||
@ -157,21 +155,21 @@ gmic_gen( VipsRegion *oreg, void *seq, void *a, void *b, gboolean *stop )
|
|||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
gmic gmic_instance;
|
gmic gmic_instance;
|
||||||
gmic_list<float> images;
|
gmic_list<T> images;
|
||||||
gmic_list<char> images_names;
|
gmic_list<char> images_names;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
images.assign( (guint) ninput );
|
images.assign( (guint) ninput );
|
||||||
|
|
||||||
for( int i = 0; ir[i]; i++ ) {
|
for( int i = 0; ir[i]; i++ ) {
|
||||||
gmic_image<float> &img = images._data[i];
|
gmic_image<T> &img = images._data[i];
|
||||||
img.assign( need.width, need.height,
|
img.assign( need.width, need.height,
|
||||||
1, ir[i]->im->Bands );
|
1, ir[i]->im->Bands );
|
||||||
vips_to_gmic( ir[0], &need, &img );
|
vips_to_gmic<T>( ir[0], &need, &img );
|
||||||
}
|
}
|
||||||
|
|
||||||
gmic_instance.run( vipsgmic->command, images, images_names );
|
gmic_instance.run( vipsgmic->command, images, images_names );
|
||||||
gmic_to_vips( &images._data[0], &need, oreg );
|
vips_from_gmic<T>( &images._data[0], &need, oreg );
|
||||||
}
|
}
|
||||||
catch( gmic_exception e ) {
|
catch( gmic_exception e ) {
|
||||||
images.assign( (guint) 0 );
|
images.assign( (guint) 0 );
|
||||||
@ -186,7 +184,56 @@ gmic_gen( VipsRegion *oreg, void *seq, void *a, void *b, gboolean *stop )
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_gmic_build( VipsObject *object )
|
vips_gmic_gen( VipsRegion *oreg, void *seq, void *a, void *b, gboolean *stop )
|
||||||
|
{
|
||||||
|
VipsRegion **ir = (VipsRegion **) seq;
|
||||||
|
|
||||||
|
switch( ir[0]->im->BandFmt ) {
|
||||||
|
case VIPS_FORMAT_UCHAR:
|
||||||
|
return( vips_gmic_gen_template<unsigned char>( oreg,
|
||||||
|
seq, a, b, stop ) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIPS_FORMAT_USHORT:
|
||||||
|
return( vips_gmic_gen_template<unsigned short int>( oreg,
|
||||||
|
seq, a, b, stop ) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIPS_FORMAT_FLOAT:
|
||||||
|
return( vips_gmic_gen_template<float>( oreg,
|
||||||
|
seq, a, b, stop ) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
g_assert( 0 );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Save a bit of typing.
|
||||||
|
*/
|
||||||
|
#define UC VIPS_FORMAT_UCHAR
|
||||||
|
#define C VIPS_FORMAT_CHAR
|
||||||
|
#define US VIPS_FORMAT_USHORT
|
||||||
|
#define S VIPS_FORMAT_SHORT
|
||||||
|
#define UI VIPS_FORMAT_UINT
|
||||||
|
#define I VIPS_FORMAT_INT
|
||||||
|
#define F VIPS_FORMAT_FLOAT
|
||||||
|
#define X VIPS_FORMAT_COMPLEX
|
||||||
|
#define D VIPS_FORMAT_DOUBLE
|
||||||
|
#define DX VIPS_FORMAT_DPCOMPLEX
|
||||||
|
|
||||||
|
/* Type promotion.
|
||||||
|
*/
|
||||||
|
static const VipsBandFormat vips_gmic_format_table[10] = {
|
||||||
|
/* UC C US S UI I F X D DX */
|
||||||
|
UC, F, US, F, F, F, F, F, F, F
|
||||||
|
};
|
||||||
|
|
||||||
|
static int
|
||||||
|
vips_gmic_build( VipsObject *object )
|
||||||
{
|
{
|
||||||
VipsObjectClass *klass = VIPS_OBJECT_GET_CLASS( object );
|
VipsObjectClass *klass = VIPS_OBJECT_GET_CLASS( object );
|
||||||
VipsGMic *vipsgmic = (VipsGMic *) object;
|
VipsGMic *vipsgmic = (VipsGMic *) object;
|
||||||
@ -194,21 +241,27 @@ _gmic_build( VipsObject *object )
|
|||||||
VipsImage **in;
|
VipsImage **in;
|
||||||
VipsImage **t;
|
VipsImage **t;
|
||||||
int ninput;
|
int ninput;
|
||||||
int i;
|
VipsBandFormat format;
|
||||||
|
|
||||||
if( VIPS_OBJECT_CLASS( vips_gmic_parent_class )->build( object ) )
|
if( VIPS_OBJECT_CLASS( vips_gmic_parent_class )->build( object ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
in = vips_array_image_get( vipsgmic->in, &ninput );
|
in = vips_array_image_get( vipsgmic->in, &ninput );
|
||||||
|
|
||||||
for( i = 0; i < ninput; i++ )
|
for( int i = 0; i < ninput; i++ )
|
||||||
if( vips_image_pio_input( in[i] ) ||
|
if( vips_image_pio_input( in[i] ) ||
|
||||||
vips_check_coding_known( klass->nickname, in[i] ) )
|
vips_check_coding_known( klass->nickname, in[i] ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
|
/* Cast all inputs up to the largest common supported format.
|
||||||
|
*/
|
||||||
|
format = VIPS_FORMAT_UCHAR;
|
||||||
|
for( int i = 0; i < ninput; i++ )
|
||||||
|
format = VIPS_MAX( format, in[i]->BandFmt );
|
||||||
|
format = vips_gmic_format_table[format];
|
||||||
t = (VipsImage **) vips_object_local_array( object, ninput );
|
t = (VipsImage **) vips_object_local_array( object, ninput );
|
||||||
for( i = 0; i < ninput; i++ )
|
for( int i = 0; i < ninput; i++ )
|
||||||
if( vips_cast( in[i], &t[i], VIPS_FORMAT_FLOAT, NULL ) )
|
if( vips_cast( in[i], &t[i], format, NULL ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
in = t;
|
in = t;
|
||||||
|
|
||||||
@ -220,13 +273,14 @@ _gmic_build( VipsObject *object )
|
|||||||
|
|
||||||
if( ninput > 0 ) {
|
if( ninput > 0 ) {
|
||||||
if( vips_image_generate( vipsgmic->out,
|
if( vips_image_generate( vipsgmic->out,
|
||||||
vips_start_many, gmic_gen, vips_stop_many,
|
vips_start_many, vips_gmic_gen, vips_stop_many,
|
||||||
in, vipsgmic ) )
|
in, vipsgmic ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if( vips_image_generate( vipsgmic->out,
|
if( vips_image_generate( vipsgmic->out,
|
||||||
NULL, gmic_gen, NULL, NULL, vipsgmic ) )
|
NULL, vips_gmic_gen, NULL,
|
||||||
|
NULL, vipsgmic ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,7 +299,7 @@ vips_gmic_class_init( VipsGMicClass *klass )
|
|||||||
|
|
||||||
vobject_class->nickname = "gmic";
|
vobject_class->nickname = "gmic";
|
||||||
vobject_class->description = _( "Vips G'MIC" );
|
vobject_class->description = _( "Vips G'MIC" );
|
||||||
vobject_class->build = _gmic_build;
|
vobject_class->build = vips_gmic_build;
|
||||||
|
|
||||||
operation_class->flags = VIPS_OPERATION_SEQUENTIAL_UNBUFFERED;
|
operation_class->flags = VIPS_OPERATION_SEQUENTIAL_UNBUFFERED;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user