<commit_before>/* use pixel values to select between an array of images
 *
 * 28/7/19
 * 	- from maplut.c
 */

/*

    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 <vips/internal.h>

typedef struct _VipsSelect {
	VipsOperation parent_instance;

	VipsArrayImage *tests;
	VipsArrayImage *cases;
	VipsImage *out;

	int n;

} VipsSelect;

typedef VipsOperationClass VipsSelectClass;

G_DEFINE_TYPE( VipsSelect, vips_select, VIPS_TYPE_OPERATION );

/* Our sequence value.
 */
typedef struct _VipsSelectSeq {
	VipsSelect *select;

	/* Set of input regions.
	 */
	VipsRegion **tests;
	VipsRegion **cases;

} VipsSelectSeq;

static void *
vips_select_start( VipsImage *out, void *a, void *b )
{
	VipsImage **in = (VipsImage **) a;
	VipsSelect *select = (VipsSelect *) b;

	VipsSelectSeq *seq;
	int i, n;

	if( !(seq = VIPS_NEW( NULL, VipsSelectSeq )) )
		return( NULL );

	seq->select = select;
	seq->tests = NULL;
	seq->cases = NULL;

	/* How many images?
	 */
	for( n = 0; in[n]; n++ )
		;

	/* Alocate space for region array.
	 */
	if( !(seq->ir = VIPS_ARRAY( NULL, n + 1, VipsRegion * )) ) {
		vips_bandary_stop( seq, NULL, NULL );
		return( NULL );
	}

	/* Create a set of regions.
	 */
	for( i = 0; i < n; i++ )
		if( !(seq->ir[i] = vips_region_new( in[i] )) ) {
			vips_bandary_stop( seq, NULL, NULL );
			return( NULL );
		}
	seq->ir[n] = NULL;

	/* Input pointers.
	 */
	if( !(seq->p = VIPS_ARRAY( NULL, n + 1, VipsPel * )) ) {
		vips_bandary_stop( seq, NULL, NULL );
		return( NULL );
	}

	/* Pixel buffer. This is used as working space by some subclasses.
	 */
	if( !(seq->pixels = VIPS_ARRAY( NULL, 
		n * VIPS_IMAGE_SIZEOF_PEL( bandary->ready[0] ), VipsPel )) ) {
		vips_bandary_stop( seq, NULL, NULL );
		return( NULL );
	}

	return( seq );
}


need start / stop and a seq typedef for our two arrays of regions

/* Do a map.
 */
static int 
vips_select_gen( VipsRegion *or, void *seq, void *a, void *b, 
	gboolean *stop )
{
	VipsRegion **ar = (VipsRegion **) seq;
	VipsSelect *swit = (VipsSelect *) b;
	VipsRect *r = &or->valid;
	VipsRegion *index = ar[swit->n];

	int x, y, i, j;
	VipsPel * restrict ip;
	VipsPel * restrict q;
	size_t ils;
	size_t qls;
	int hist[256];
	VipsPel * restrict p[256];
	size_t ls[256];
	size_t ps;

	if( vips_region_prepare( index, r ) )
		return( -1 );

	g_assert( index->im->BandFmt == VIPS_FORMAT_UCHAR );
	g_assert( index->im->Bands == 1 );<commit_msg>more hacking<commit_after>/* use pixel values to select between an array of images
 *
 * 28/7/19
 * 	- from maplut.c
 */

/*

    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 <vips/internal.h>

typedef struct _VipsSelect {
	VipsOperation parent_instance;

	VipsArrayImage *tests;
	VipsArrayImage *cases;
	VipsImage *out;

	int n;

} VipsSelect;

typedef VipsOperationClass VipsSelectClass;

G_DEFINE_TYPE( VipsSelect, vips_select, VIPS_TYPE_OPERATION );

/* Our sequence value.
 */
typedef struct _VipsSelectSeq {
	VipsSelect *select;

	/* Set of input regions.
	 */
	VipsRegion **tests;
	VipsRegion **cases;

} VipsSelectSeq;

int
vips_select_stop( void *vseq, void *a, void *b )
{
	VipsSelectSeq *seq = (VipsSelectSeq *) vseq;

	if( seq->tests ) {
		vips_stop_many( (void *) seq->tests, NULL, NULL );
		seq->tests = NULL;
	}
	if( seq->cases ) {
		vips_stop_many( (void *) seq->cases, NULL, NULL );
		seq->cases = NULL;
	}
	VIPS_FREE( seq );

	return( 0 ):
}

static void *
vips_select_start( VipsImage *out, void *a, void *b )
{
	VipsImage **in = (VipsImage **) a;
	VipsSelect *select = (VipsSelect *) b;

	VipsSelectSeq *seq;
	int i, n;

	if( !(seq = VIPS_NEW( NULL, VipsSelectSeq )) )
		return( NULL );

	seq->select = select;
	seq->tests = NULL;
	seq->cases = NULL;

	seq->tests = vips_start_many( NULL, (void *) select->tests, NULL );
	seq->cases = vips_start_many( NULL, (void *) select->cases, NULL );
	if( !seq->tests ||
		!seq->cases ) {
		vips_select_stop( (void *) seq, NULL, NULL  );
		return( NULL );
	}

	return( seq );
}

/* Do a map.
 */
static int 
vips_select_gen( VipsRegion *or, void *vseq, void *a, void *b, 
	gboolean *stop )
{
	VipsSelectSeq *seq = (VipsSelectSeq *) vseq;
	VipsSelect *select = seq->select;
	VipsRect *r = &or->valid;

	int x, y, i, j;
	VipsPel * restrict ip;
	VipsPel * restrict q;
	size_t ils;
	size_t qls;
	int hist[256];
	VipsPel * restrict p[256];
	size_t ls[256];
	size_t ps;

	if( vips_region_prepare( index, r ) )
		return( -1 );

	g_assert( index->im->BandFmt == VIPS_FORMAT_UCHAR );
	g_assert( index->im->Bands == 1 );
{'fraction_non_alphanumeric': 0.12376237623762376, 'fraction_numerical': 0.009591584158415841, 'mean_word_length': 3.4009530292716135, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4794295', 'n_tokens_mistral': 2467, 'n_tokens_neox': 2328, 'n_words': 757}