Esempio n. 1
0
/*! \brief Filter paired-end reads by patterns
 *
 *  \param[in]  reads1_f    an input stream of paired-end read 1 sequences
 *  \param[in]  reads2_f    an input stream of paired-end read 2 sequences
 *  \param[out] ok1_f       an output stream to write filtered paired-end read 1 sequences to
 *  \param[out] ok2_f       an output stream to write filtered paired-end read 2 sequences to
 *  \param[out] stats1      statistics on first parts of processed reads
 *  \param[out] stats2      statistics on second parts of processed reads
 *  \param[in]  root        a root of the trie structure used to perform string matching
 *  \param[in]  patterns    a vector of patterns for read filtration
 *  \param[in]  length      the read length threshold
 *  \param[in]  dust_k      the DUST algorithm parameter
 *  \param[in]  dust_cutoff the DUST score threshold
 *  \param[in]  errors      the number of resolved mismatches between a read and
 *                          a pattern
 */
void filter_paired_reads(std::ifstream & reads1_f, std::ifstream & reads2_f,
                         std::ofstream & ok1_f, std::ofstream & ok2_f,
                         Stats & stats1, Stats & stats2,
                         Node * root, std::vector <std::pair<std::string, Node::Type> > const & patterns, int errors)
{
    Seq read1;
    Seq read2;
    int processed = 0;

    while (read1.read_seq(reads1_f) && read2.read_seq(reads2_f)) {
        ReadType type1 = check_read(read1.seq, root, patterns, 0, 0, 0, errors);
        ReadType type2 = check_read(read2.seq, root, patterns, 0, 0, 0, errors);
        if (type1 == ReadType::ok && type2 == ReadType::ok) {
            read1.write_seq(ok1_f);
            read2.write_seq(ok2_f);
            stats1.update(type1, true);
            stats2.update(type2, true);
        } else {
            stats1.update(type1, false);
            stats2.update(type2, false);
        }

        processed += 1;
        if (processed % 1000000 == 0) {
            std::cerr << "Processed: " << processed << std::endl;
        }
    }
}
Esempio n. 2
0
/* <array|dict|name|packedarray|string> length <int> */
static int
zlength(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    switch (r_type(op)) {
	case t_array:
	case t_string:
	case t_mixedarray:
	case t_shortarray:
	    check_read(*op);
	    make_int(op, r_size(op));
	    return 0;
	case t_dictionary:
	    check_dict_read(*op);
	    make_int(op, dict_length(op));
	    return 0;
	case t_name: {
	    ref str;

	    name_string_ref(imemory, op, &str);
	    make_int(op, r_size(&str));
	    return 0;
	}
	case t_astruct:
	    if (gs_object_type(imemory, op->value.pstruct) != &st_bytes)
		return_error(e_typecheck);
	    check_read(*op);
	    make_int(op, gs_object_size(imemory, op->value.pstruct));
	    return 0;
	default:
	    return_op_typecheck(op);
    }
}
Esempio n. 3
0
static rtems_task Init(rtems_task_argument argument)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  rtems_bdbuf_buffer *bd = NULL;
  dev_t dev = 0;
  rtems_disk_device *dd = NULL;

  printk("\n\n*** TEST BLOCK 9 ***\n");

  sc = rtems_disk_io_initialize();
  ASSERT_SC(sc);

  sc = disk_register(BLOCK_SIZE, BLOCK_COUNT, &dev);
  ASSERT_SC(sc);

  dd = rtems_disk_obtain(dev);
  assert(dd != NULL);

  check_read(dd, BLOCK_READ_IO_ERROR, RTEMS_IO_ERROR);
  check_read(dd, BLOCK_READ_UNSATISFIED, RTEMS_UNSATISFIED);
  check_read(dd, BLOCK_READ_SUCCESSFUL, RTEMS_SUCCESSFUL);
  check_read(dd, BLOCK_WRITE_IO_ERROR, RTEMS_SUCCESSFUL);

  /* Check write IO error */

  sc = rtems_bdbuf_read(dd, BLOCK_WRITE_IO_ERROR, &bd);
  ASSERT_SC(sc);

  bd->buffer [0] = 1;

  sc = rtems_bdbuf_sync(bd);
  ASSERT_SC(sc);

  sc = rtems_bdbuf_read(dd, BLOCK_WRITE_IO_ERROR, &bd);
  ASSERT_SC(sc);

  assert(bd->buffer [0] == 0);

  sc = rtems_bdbuf_release(bd);
  ASSERT_SC(sc);

  /* Check write to deleted disk */

  sc = rtems_bdbuf_read(dd, BLOCK_READ_SUCCESSFUL, &bd);
  ASSERT_SC(sc);

  sc = rtems_disk_delete(dev);
  ASSERT_SC(sc);

  sc = rtems_bdbuf_sync(bd);
  ASSERT_SC(sc);

  sc = rtems_disk_release(dd);
  ASSERT_SC(sc);

  printk("*** END OF TEST BLOCK 9 ***\n");

  exit(0);
}
Esempio n. 4
0
static int
zforall(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    os_ptr obj = op - 1;
    es_ptr ep = esp;
    es_ptr cproc = ep + 4;

    check_estack(6);
    check_proc(*op);
    switch (r_type(obj)) {
	default:
	    return_op_typecheck(obj);
	case t_array:
	    check_read(*obj);
	    make_op_estack(cproc, array_continue);
	    break;
	case t_dictionary:
	    check_dict_read(*obj);
	    make_int(cproc, dict_first(obj));
	    ++cproc;
	    make_op_estack(cproc, dict_continue);
	    break;
	case t_string:
	    check_read(*obj);
	    make_op_estack(cproc, string_continue);
	    break;
	case t_mixedarray:
	case t_shortarray:
	    check_read(*obj);
	    make_op_estack(cproc, packedarray_continue);
	    break;
    }
    /*
     * Push:
     *   - a mark;
     *   - the composite object;
     *   - the procedure;
     *   - the iteration index (only for dictionaries, done above);
     * and invoke the continuation operator.
     */
    make_mark_estack(ep + 1, es_for, forall_cleanup);
    ep[2] = *obj;
    ep[3] = *op;
    esp = cproc - 1;
    pop(2);
    return (*real_opproc(cproc))(i_ctx_p);
}
Esempio n. 5
0
        //  Applies the function fn to the first elemenent in the pipe
        //  and returns the value returned by the fn.
        //  The pipe mustn't be empty or the function crashes.
        inline bool probe (bool (*fn)(T &))
        {
                bool rc = check_read ();
                zmq_assert (rc);

                return (*fn) (queue.front ());
        }
Esempio n. 6
0
/* void Arduino50::checkpoint()
 * @param1: int checkpoint_id 
 * purpose: based on the checkpoint id, obtains the correct solution object
 */
void 
Arduino50::checkpoint(int checkpoint_id)
{	
	// get the specific solution for this checkpoint
	solution s = outputs[checkpoint_id];
	
	// based on the ENUM to Solution.Type pairing, check the current input
	switch(s.type)
	{
		case READ:
			inputs[checkpoint_id] = check_read(s);
		break;
		case PIN:
			inputs[checkpoint_id] = check_pin(s);			
		break;
		case NUMBER:
			inputs[checkpoint_id] = check_number(s);
		break;
		case MODE:
		break;
		default:
		break;
	}

}
Esempio n. 7
0
/* <obj> <pattern> .stringmatch <bool> */
static int
zstringmatch(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    os_ptr op1 = op - 1;
    bool result;

    check_read_type(*op, t_string);
    switch (r_type(op1)) {
        case t_string:
            check_read(*op1);
            goto cmp;
        case t_name:
            name_string_ref(imemory, op1, op1);	/* can't fail */
cmp:
            result = string_match(op1->value.const_bytes, r_size(op1),
                                  op->value.const_bytes, r_size(op),
                                  NULL);
            break;
        default:
            result = (r_size(op) == 1 && *op->value.bytes == '*');
    }
    make_bool(op1, result);
    pop(1);
    return 0;
}
Esempio n. 8
0
/* token */
int
ztoken(register os_ptr op)
{	stream st;
	stream *s = &st;
	int code;
	ref token;
	switch ( r_type(op) )
	   {
	default: return e_typecheck;
	case t_file: return ztoken_file(op);
	case t_string: ;
	   }
	check_read(*op);
	sread_string(s, op->value.bytes, r_size(op));
	switch ( code = scan_token(s, 1, &token) )
	   {
	case 0:				/* read a token */
	   {	uint pos = stell(s);
		op->value.bytes += pos;
		r_inc_size(op, -pos);
	   }
		push(2);
		op[-1] = token;
		make_bool(op, 1);
		return 0;
	case 1:				/* no tokens */
		make_bool(op, 0);
		return 0;
	default:			/* error */
		return code;
	   }
}
Esempio n. 9
0
static void read_cb(struct ev_loop *loop, struct ev_io *w, int revents)
{ 
	
	struct client *cli = (struct client *)w;
	int n = 0;
	char rbuff[5];
	assert(revents == EV_READ);
	for (;;) {
		n = check_read(cli->fd, rbuff, sizeof(rbuff));
		if (n <= 0) {
			break;
		} else {
			// echo
			int s_n = check_write(cli->fd, rbuff, n);
			if (s_n < n) {
				printf("send buffer full\n");
				break;
			}
			if (s_n < 0) {
				// something err
				break;
			}
		}
		//sleep(1);
	}
	printf("ECHO OVER\n");

	ev_io_stop(EV_A_ w);
 	close(cli->fd);
	free(cli);

	
}
Esempio n. 10
0
/* Return <0 for error, or a number format. */
int
num_array_format(const ref * op)
{
    int format;

    switch (r_type(op)) {
	case t_string:
	    {
		/* Check that this is a legitimate encoded number string. */
		const byte *bp = op->value.bytes;

		if (r_size(op) < 4 || bp[0] != bt_num_array_value)
		    return_error(e_typecheck);
		format = bp[1];
		if (!num_is_valid(format) ||
		    sdecodeshort(bp + 2, format) !=
		    (r_size(op) - 4) / encoded_number_bytes(format)
		    )
		    return_error(e_rangecheck);
	    }
	    break;
	case t_array:
	case t_mixedarray:
	case t_shortarray:
	    format = num_array;
	    break;
	default:
	    return_error(e_typecheck);
    }
    check_read(*op);
    return format;
}
Esempio n. 11
0
	bool httpclient::wait_response()
	{
		if(check_read(3600 * 1000)){
			return true;
		}
		return false;
	}
Esempio n. 12
0
        //  Reads an item from the pipe. Returns false if there is no value.
        //  available.
        inline bool read (T *value_)
        {
            if (!check_read ())
                return false;

            return dbuffer.read (value_);
        }
Esempio n. 13
0
/* Return 0 if OK, error code if not. */
int
read_matrix(const gs_memory_t *mem, const ref * op, gs_matrix * pmat)
{
    int code;
    ref values[6];
    const ref *pvalues;

    switch (r_type(op)) {
	case t_array:
	    pvalues = op->value.refs;
	    break;
	case t_mixedarray:
	case t_shortarray:
	    {
		int i;

		for (i = 0; i < 6; ++i) {
		    code = array_get(mem, op, (long)i, &values[i]);
		    if (code < 0)
			return code;
		}
		pvalues = values;
	    }
	    break;
	default:
	    return_op_typecheck(op);
    }
    check_read(*op);
    if (r_size(op) != 6)
	return_error(e_rangecheck);
    code = float_params(pvalues + 5, 6, (float *)pmat);
    return (code < 0 ? code : 0);
}
Esempio n. 14
0
File: filter.c Progetto: Pency/BSPT
int filter_se_fastq_bz2(FLT_OPTS *opts){
	int index=1;
	int stat_left = 0;

	SEQ_QUAL item=init_read();
	gzFile fp=gzopen_report(opts->r1,"r");
	FILE *fo=fopen_report(strcat(opts->output,".flt"),"w+");
	int left = 0;

	while(read_fastq(fp,&item,index++) > 0){
		check_read(&item,2);
		left=filter_all(&item, opts);

		if(left == 1){
			output_fastq(fo, &item);
			stat_left++;
		}
	}

	printf("Totally %d reads were processed\n",index-1);
	printf("  file [ %s ]: %d reads were left (%.2f%)\n",opts->r1,stat_left,(float) stat_left*100/(index-1));
	free_read(&item);
	fclose(fp);
	fclose(fo);
	
	return 0;
}	
Esempio n. 15
0
 void _ByteArray::readBytes(unsigned char *val, std::size_t size, std::size_t offset)
 {
     check_read(size);
     //unsigned char *desByte = val + offset;
     unsigned char *srcByte = _bytes;
     srcByte+=rPos;
     memcpy(val + offset, srcByte, size);
     rPos += size;
 }
Esempio n. 16
0
BOOL LLVOCache::checkRead(LLAPRFile* apr_file, void* src, S32 n_bytes) 
{
	if(!check_read(apr_file, src, n_bytes))
	{
		delete apr_file ;
		removeCache() ;
		return FALSE ;
	}

	return TRUE ;
}
Esempio n. 17
0
 void read() {
   string test_string;
   test_string.resize(get_test_string().size());
   check_read(
     test_string.data(),
     get_read_channel().read(
       const_cast<char*>(test_string.data()),
       test_string.capacity()
     )
   );
 }
Esempio n. 18
0
        //  Reads an item from the pipe. Returns false if there is no value.
        //  available.
        inline bool read (T *value_)
        {
            //  Try to prefetch a value.
            if (!check_read ())
                return false;

            //  There was at least one value prefetched.
            //  Return it to the caller.
            *value_ = queue.front ();
            queue.pop ();
            return true;
        }
Esempio n. 19
0
/* Collect a Function value. */
static int
build_shading_function(i_ctx_t *i_ctx_p, const ref * op, gs_function_t ** ppfn,
                 int num_inputs, gs_memory_t *mem, const float *shading_domain)
{
    ref *pFunction;
    int code;

    *ppfn = 0;
    if (dict_find_string(op, "Function", &pFunction) <= 0)
        return 0;
    if (r_is_array(pFunction)) {
        uint size = r_size(pFunction);
        gs_function_t **Functions;
        uint i;
        gs_function_AdOt_params_t params;

        check_read(*pFunction);
        if (size == 0)
            return_error(gs_error_rangecheck);
        code = alloc_function_array(size, &Functions, mem);
        if (code < 0)
            return code;
        for (i = 0; i < size; ++i) {
            ref rsubfn;

            array_get(imemory, pFunction, (long)i, &rsubfn);
            code = fn_build_function(i_ctx_p, &rsubfn, &Functions[i], mem,
               shading_domain, num_inputs);
            if (code < 0)
                break;
        }
        params.m = num_inputs;
        params.Domain = 0;
        params.n = size;
        params.Range = 0;
        params.Functions = (const gs_function_t * const *)Functions;
        if (code >= 0)
            code = gs_function_AdOt_init(ppfn, &params, mem);
        if (code < 0)
            gs_function_AdOt_free_params(&params, mem);
    } else {
        code = fn_build_function(i_ctx_p, pFunction, ppfn, mem,
            shading_domain, num_inputs);
        if (code < 0)
            return code;
        if ((*ppfn)->params.m != num_inputs) {
            gs_function_free(*ppfn, true, mem);
            return_error(gs_error_rangecheck);
        }
    }
    return code;
}
Esempio n. 20
0
/*! \brief Filter paired-end reads by patterns
 *
 *  \param[in]  reads1_f    an input stream of paired-end read 1 sequences
 *  \param[in]  reads2_f    an input stream of paired-end read 2 sequences
 *  \param[out] ok1_f       an output stream to write filtered paired-end read 1 sequences to
 *  \param[out] ok2_f       an output stream to write filtered paired-end read 2 sequences to
 *  \param[out] bad1_f      an output stream to write filtered out paired-end read 1 sequences to
 *  \param[out] bad2_f      an output stream to write filtered out paired-end read 2 sequences to
 *  \param[out] se1_f       an output stream to write filtered first parts of paired-end reads
 *  \param[out] se2_f       an output stream to write filtered second parts of paired-end reads
 *  \param[out] stats1      statistics on first parts of processed reads
 *  \param[out] stats2      statistics on second parts of processed reads
 *  \param[in]  root        a root of the trie structure used to perform string matching
 *  \param[in]  patterns    a vector of patterns for read filtration
 *  \param[in]  length      the read length threshold
 *  \param[in]  dust_k      the DUST algorithm parameter
 *  \param[in]  dust_cutoff the DUST score threshold
 *  \param[in]  errors      the number of resolved mismatches between a read and
 *                          a pattern
 *
 *  \remark The streams \p se1_f (and \p se2_f) correspond to paired-end reads which second
 *  (or first) part was filtered but the other one was left.
 */
void filter_paired_reads(std::ifstream & reads1_f, std::ifstream & reads2_f,
                         std::ofstream & ok1_f, std::ofstream & ok2_f,
                         std::ofstream & bad1_f, std::ofstream & bad2_f,
                         std::ofstream & se1_f, std::ofstream & se2_f,
                         Stats & stats1, Stats & stats2,
                         Node * root, std::vector <std::pair<std::string, Node::Type> > const & patterns,
                         int length, int dust_k, int dust_cutoff, int errors)
{
    Seq read1;
    Seq read2;

    while (read1.read_seq(reads1_f) && read2.read_seq(reads2_f)) {
        ReadType type1 = check_read(read1.seq, root, patterns, length, dust_k, dust_cutoff, errors);
        ReadType type2 = check_read(read2.seq, root, patterns, length, dust_k, dust_cutoff, errors);
        if (type1 == ReadType::ok && type2 == ReadType::ok) {
            read1.write_seq(ok1_f);
            read2.write_seq(ok2_f);
            stats1.update(type1, true);
            stats2.update(type2, true);
        } else {
            stats1.update(type1, false);
            stats2.update(type2, false);
            if (type1 == ReadType::ok) {
                read1.write_seq(se1_f);
                read2.update_id(type2);
                read2.write_seq(bad2_f);
            } else if (type2 == ReadType::ok) { 
                read1.update_id(type1);
                read1.write_seq(bad1_f);
                read2.write_seq(se2_f);
            } else {
                read1.update_id(type1);
                read2.update_id(type2);
                read1.write_seq(bad1_f);
                read2.write_seq(bad2_f);
            }
        }
    }
}
Esempio n. 21
0
/* Calculate bonding box of a box transformed by a matrix. */
static int
zbbox_transform(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    gs_matrix m;
    float bbox[4];
    gs_point aa, az, za, zz;
    double temp;
    int code;

    if ((code = read_matrix(imemory, op, &m)) < 0)
        return code;

    if (!r_is_array(op - 1))
        return_op_typecheck(op - 1);
    check_read(op[-1]);
    if (r_size(op - 1) != 4)
        return_error(gs_error_rangecheck);
    if ((code = process_float_array(imemory, op - 1, 4, bbox) < 0))
        return code;

    gs_point_transform(bbox[0], bbox[1], &m, &aa);
    gs_point_transform(bbox[0], bbox[3], &m, &az);
    gs_point_transform(bbox[2], bbox[1], &m, &za);
    gs_point_transform(bbox[2], bbox[3], &m, &zz);

    if ( aa.x > az.x)
        temp = aa.x, aa.x = az.x, az.x = temp;
    if ( za.x > zz.x)
        temp = za.x, za.x = zz.x, zz.x = temp;
    if ( za.x < aa.x)
        aa.x = za.x;  /* min */
    if ( az.x > zz.x)
        zz.x = az.x;  /* max */

    if ( aa.y > az.y)
        temp = aa.y, aa.y = az.y, az.y = temp;
    if ( za.y > zz.y)
        temp = za.y, za.y = zz.y, zz.y = temp;
    if ( za.y < aa.y)
        aa.y = za.y;  /* min */
    if ( az.y > zz.y)
        zz.y = az.y;  /* max */

    push(2);
    make_real(op - 3, (float)aa.x);
    make_real(op - 2, (float)aa.y);
    make_real(op - 1, (float)zz.x);
    make_real(op    , (float)zz.y);
    return 0;
}
Esempio n. 22
0
TYPED_TEST_P(ChannelTest, readv_one) {
  this->write();

  string test_string;
  test_string.resize(this->get_test_string().size());
  iovec iov;
  iov.iov_base = const_cast<char*>(test_string.data());
  iov.iov_len = test_string.size();

  check_read(
    test_string.data(),
    this->get_read_channel().readv(&iov, 1)
  );
}
Esempio n. 23
0
/* <gstate> setgstate - */
int
zsetgstate(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    int code;

    check_stype(*op, st_igstate_obj);
    check_read(*op);
    code = gs_setgstate(igs, igstate_ptr(op));
    if (code < 0)
	return code;
    pop(1);
    return 0;
}
Esempio n. 24
0
/* <dict> <key> get <obj> */
static int
zget(i_ctx_t *i_ctx_p)
{
    int code;
    os_ptr op = osp;
    os_ptr op1 = op - 1;
    ref *pvalue;

    switch (r_type(op1)) {
	case t_dictionary:
	    check_dict_read(*op1);
	    if (dict_find(op1, op, &pvalue) <= 0)
		return_error(e_undefined);
	    op[-1] = *pvalue;
	    break;
	case t_string:
	    check_read(*op1);
	    check_int_ltu(*op, r_size(op1));
	    make_int(op1, op1->value.bytes[(uint) op->value.intval]);
	    break;
	case t_array:
	case t_mixedarray:
	case t_shortarray:
	    check_type(*op, t_integer);
	    check_read(*op1);
	    code = array_get(imemory, op1, op->value.intval, op1);
	    if (code < 0) 
	        return code;
	    break;
        case t__invalid:
            return_error(e_stackunderflow);
        default:
            return_error(e_typecheck); 
    }
    pop(1);
    return 0;
}
Esempio n. 25
0
/* its length; nothing else has been checked. */
static int
copy_interval(i_ctx_t *i_ctx_p /* for ref_assign_old */, os_ptr prto,
	      uint index, os_ptr prfrom, client_name_t cname)
{
    int fromtype = r_type(prfrom);
    uint fromsize = r_size(prfrom);

    if (!(fromtype == r_type(prto) ||
	  ((fromtype == t_shortarray || fromtype == t_mixedarray) &&
	   r_type(prto) == t_array))
	)
	return_op_typecheck(prfrom);
    check_read(*prfrom);
    check_write(*prto);
    if (fromsize > r_size(prto) - index)
	return_error(e_rangecheck);
    switch (fromtype) {
	case t_array:
	    {			/* We have to worry about aliasing, */
		/* but refcpy_to_old takes care of it for us. */
		return refcpy_to_old(prto, index, prfrom->value.refs,
				     fromsize, idmemory, cname);
	    }
	case t_string:
	    {	/* memmove takes care of aliasing. */
		memmove(prto->value.bytes + index, prfrom->value.bytes,
			fromsize);
	    }
	    break;
	case t_mixedarray:
	case t_shortarray:
	    {	/* We don't have to worry about aliasing, because */
		/* packed arrays are read-only and hence the destination */
		/* can't be a packed array. */
		uint i;
		const ref_packed *packed = prfrom->value.packed;
		ref *pdest = prto->value.refs + index;
		ref elt;

		for (i = 0; i < fromsize; i++, pdest++) {
		    packed_get(imemory, packed, &elt);
		    ref_assign_old(prto, pdest, &elt, cname);
		    packed = packed_next(packed);
		}
	    }
	    break;
    }
    return 0;
}
Esempio n. 26
0
/* Common code for composite and dissolve. */
static int
composite_image(i_ctx_t *i_ctx_p, const gs_composite_alpha_params_t * params)
{
    os_ptr op = osp;
    alpha_composite_state_t cstate;
    gs_image2_t image;
    double src_rect[4];
    double dest_pt[2];
    gs_matrix save_ctm;
    int code = xywh_param(op - 4, src_rect);

    cstate.params = *params;
    gs_image2_t_init(&image);
    if (code < 0 ||
        (code = num_params(op - 1, 2, dest_pt)) < 0
        )
        return code;
    if (r_has_type(op - 3, t_null))
        image.DataSource = igs;
    else {
        check_stype(op[-3], st_igstate_obj);
        check_read(op[-3]);
        image.DataSource = igstate_ptr(op - 3);
    }
    image.XOrigin = src_rect[0];
    image.YOrigin = src_rect[1];
    image.Width = src_rect[2];
    image.Height = src_rect[3];
    image.PixelCopy = true;
    /* Compute appropriate transformations. */
    gs_currentmatrix(igs, &save_ctm);
    gs_translate(igs, dest_pt[0], dest_pt[1]);
    gs_make_identity(&image.ImageMatrix);
    if (image.DataSource == igs) {
        image.XOrigin -= dest_pt[0];
        image.YOrigin -= dest_pt[1];
    }
    code = begin_composite(i_ctx_p, &cstate);
    if (code >= 0) {
        code = process_non_source_image(i_ctx_p,
                                        (const gs_image_common_t *)&image,
                                        "composite_image");
        end_composite(i_ctx_p, &cstate);
        if (code >= 0)
            pop(8);
    }
    gs_setmatrix(igs, &save_ctm);
    return code;
}
Esempio n. 27
0
/* BitsPerSample. */
static int
dict_threshold2_params(const ref * pdict, gs_threshold2_halftone * ptp,
		       ref * ptproc, gs_memory_t *mem)
{
    ref *tstring;
    int code =
	dict_threshold_common_params(pdict,
				     (gs_threshold_halftone_common *)ptp,
				     &tstring, ptproc);
    int bps;
    uint size;
    int cw2, ch2;

    if (code < 0 ||
	(code = cw2 = dict_int_param(pdict, "Width2", 0, 0x7fff, 0,
				     &ptp->width2)) < 0 ||
	(code = ch2 = dict_int_param(pdict, "Height2", 0, 0x7fff, 0,
				     &ptp->height2)) < 0 ||
	(code = dict_int_param(pdict, "BitsPerSample", 8, 16, -1, &bps)) < 0
	)
	return code;
    if ((bps != 8 && bps != 16) || cw2 != ch2 ||
	(!cw2 && (ptp->width2 == 0 || ptp->height2 == 0))
	)
	return_error(e_rangecheck);
    ptp->bytes_per_sample = bps / 8;
    switch (r_type(tstring)) {
    case t_string:
	size = r_size(tstring);
	gs_bytestring_from_string(&ptp->thresholds, tstring->value.const_bytes,
				  size);
	break;
    case t_astruct:
	if (gs_object_type(mem, tstring->value.pstruct) != &st_bytes)
	    return_error(e_typecheck);
	size = gs_object_size(mem, tstring->value.pstruct);
	gs_bytestring_from_bytes(&ptp->thresholds, r_ptr(tstring, byte),
				 0, size);
	break;
    default:
	return_error(e_typecheck);
    }
    check_read(*tstring);
    if (size != (ptp->width * ptp->height + ptp->width2 * ptp->height2) *
	ptp->bytes_per_sample)
	return_error(e_rangecheck);
    return 0;
}
Esempio n. 28
0
TYPED_TEST_P(ChannelTest, readv_two) {
  this->write();

  string test_string;
  test_string.resize(this->get_test_string().size());
  iovec iov[2];
  iov[0].iov_base = const_cast<char*>(test_string.data());
  iov[0].iov_len = 4;
  iov[1].iov_base = const_cast<char*>(test_string.data()) + 4;
  iov[1].iov_len = 7;

  check_read(
    test_string.data(),
    this->get_read_channel().readv(iov, 2)
  );
}
Esempio n. 29
0
/*! \brief Filter single-end reads by patterns
 *
 *  \param[in]  reads_f     an input stream of read sequences
 *  \param[out] ok_f        an output stream of filtered reads
 *  \param[out] bad_f       an output stream of reads filtered out
 *  \param[out] stats       statistics on processed reads
 *  \param[out] root        a root of the trie structure used to perform string matching
 *  \param[in]  patterns    a vector of patterns for read filtration
 *  \param[in]  length      the read length threshold
 *  \param[in]  dust_k      the DUST algorithm parameter
 *  \param[in]  dust_cutoff the DUST score threshold
 *  \param[in]  errors      the number of resolved mismatches between a read and
 *                          a pattern
 */
void filter_single_reads(std::ifstream & reads_f, std::ofstream & ok_f, std::ofstream & bad_f, 
                         Stats & stats, Node * root, std::vector <std::pair<std::string, Node::Type> > const & patterns,
                         int length, int dust_k, int dust_cutoff, int errors)
{
    Seq read;

    while (read.read_seq(reads_f)) {
        ReadType type = check_read(read.seq, root, patterns, length, dust_k, dust_cutoff, errors);
        stats.update(type);
        if (type == ReadType::ok) {
            read.write_seq(ok_f);
        } else {
            read.update_id(type);
            read.write_seq(bad_f);
        }
    }
}
Esempio n. 30
0
/* <seq:array|packedarray|string> <index> <count> getinterval <subseq> */
static int
zgetinterval(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    os_ptr op1 = op - 1;
    os_ptr op2 = op1 - 1;
    uint index;
    uint count;

    switch (r_type(op2)) {
	default:
	    return_op_typecheck(op2);
	case t_array:
	case t_string:
	case t_mixedarray:
	case t_shortarray:;
    }
    check_read(*op2);
    check_int_leu(*op1, r_size(op2));
    index = op1->value.intval;
    check_int_leu(*op, r_size(op2) - index);
    count = op->value.intval;
    switch (r_type(op2)) {
	case t_array:
	    op2->value.refs += index;
	    break;
	case t_string:
	    op2->value.bytes += index;
	    break;
	case t_mixedarray: {
	    const ref_packed *packed = op2->value.packed;

	    for (; index--;)
		packed = packed_next(packed);
	    op2->value.packed = packed;
	    break;
	}
	case t_shortarray:
	    op2->value.packed += index;
	    break;
    }
    r_set_size(op2, count);
    pop(2);
    return 0;
}