Ejemplo n.º 1
0
static int rle_compress(unsigned char *dst, unsigned char *src, int n,
			int nbytes)
{
    int nwrite = 0;
    int total = nbytes * n;

    while (n > 0) {
	int count;

	nwrite += nbytes + 1;
	if (nwrite >= total)
	    return 0;

	count = count_run(src, n, nbytes);

	*dst++ = count;
	memcpy(dst, src, nbytes);
	dst += nbytes;

	src += count * nbytes;
	n -= count;
    }

    return nwrite;
}
Ejemplo n.º 2
0
/*
 *  Tries to allocate a set of blocks.	The request size depends on the
 *  type: for inodes, we must allocate sbi->s_mirrors blocks, and for file
 *  blocks, we try to allocate sbi->s_clustersize, but can always get away
 *  with just one block.
 */
int omfs_allocate_range(struct super_block *sb,
			int min_request,
			int max_request,
			u64 *return_block,
			int *return_size)
{
	struct omfs_sb_info *sbi = OMFS_SB(sb);
	int bits_per_entry = 8 * sb->s_blocksize;
	int ret = 0;
	int i, run, bit;

	mutex_lock(&sbi->s_bitmap_lock);
	for (i = 0; i < sbi->s_imap_size; i++) {
		bit = 0;
		while (bit < bits_per_entry) {
			bit = find_next_zero_bit(sbi->s_imap[i], bits_per_entry,
				bit);

			if (bit == bits_per_entry)
				break;

			run = count_run(&sbi->s_imap[i], bits_per_entry,
				sbi->s_imap_size-i, bit, max_request);

			if (run >= min_request)
				goto found;
			bit += run;
		}
	}
	ret = -ENOSPC;
	goto out;

found:
	*return_block = i * bits_per_entry + bit;
	*return_size = run;
	ret = set_run(sb, i, bits_per_entry, bit, run, 1);

out:
	mutex_unlock(&sbi->s_bitmap_lock);
	return ret;
}
Ejemplo n.º 3
0
Archivo: hw2.cpp Proyecto: j0x7c4/cvhw
void CVHW::run_length ( cv::Mat& t_image, int flag )
{
	int m = t_image.rows;
	int n = t_image.cols;
	int p,q,plast,qlast;
	int new_label=0;
	count_run(t_image); //count run

	

	//initialize run_table
	initialize_run_table( t_image);

	//top-down pass
	for ( int i = 0 ; i<m ; i++ )
	{
		p = row_start[i];
		if ( p==0 )
			continue;
		plast = row_end[i];

		if ( i==0 )
		{
			q=qlast = 0;
		}
		else
		{
			q=row_start[i-1], qlast=row_end[i-1];
		}

		while ( p<=plast && q<=qlast && q )
		{
			if ( end_col[p] < start_col[q] ) p++;
			else if ( end_col[q] < start_col[p] ) q++;
			else
			{
				int plabel = perm_label[p];
				if ( plabel == 0 ) 
					perm_label[p] = perm_label[q];
				else if ( plabel && perm_label[q]!=plabel )
					make_equivalent(perm_label[p],perm_label[q]);
				if ( end_col[p] > end_col[q] )	
					q++;
				else if ( end_col[q] > end_col[p] )
					p++;
				else if ( end_col[q] == end_col[p] )
					q++,p++;
			}
		}

		p = row_start[i];
		while( p<=plast)
		{
			int plabel = perm_label[p];
			if ( plabel == 0 )
			{
				perm_label[p] = ++new_label;
			}
			else if ( plabel && label[plabel] )
			{
				perm_label[p] = label[plabel];
			}
			p++;
		}
	}

	//bottom-up pass
	for  ( int i=m-1 ; i>=0 ; i-- )
	{
		p = row_start[i];
		if ( p==0 ) 
			continue;
		plast = row_end[i];
		if ( i == m-1 )
		{
			q=qlast = 0;
		}
		else
		{
			q=row_start[i+1];
			qlast = row_end[i+1];
		}

		while ( p<=plast && q<=qlast && q )
		{
			if ( end_col[p] < start_col[q] ) p++;
			else if ( end_col[q]< start_col[p] ) q++;
			else
			{
				if ( perm_label[p]!=perm_label[q] )
				{
					label[perm_label[p]]=perm_label[q];
					perm_label[p] = perm_label[q];
				}

				if  ( end_col[p] > end_col[q] ) q++;
				else if ( end_col[q] > end_col[p] ) p++;
				else if ( end_col[p] == end_col[q] ) q++,p++;
			}
		}
		p=row_start[i];
		while ( p<=plast )
		{
			if ( label[perm_label[p]] )
			{
				perm_label[p] =label[perm_label[p]];
			}
			p++;
		} 
	}
}