/*
 * Starting with an assumed codeword, find pairs of complementary codes with
 * certain characteristics including isolation.
 *
 * start = starting codeword for first code
 * n = length of all codewords in bits
 * min_hd = minimum hamming distance of each code
 * min_iso = minimum isolation between the two codes
 * a_len = number of codewords for first code
 * min_b_len = minimum number of codewords for second code
 */
uint16_t find_iso_from_start(uint16_t start, uint8_t n, uint8_t min_hd,
		uint8_t min_iso, uint16_t a_len, uint16_t min_b_len)
{
	uint16_t code[MAX_CAND];
	uint16_t next_candidates[MAX_CAND];
	uint16_t next_b_candidates[MAX_CAND];
	uint16_t icand = 1<<n;
	uint16_t candidates[icand];
	int i;
	uint16_t nc, bc;
	uint16_t inext_cand = 0;
	uint16_t inext_b_cand = 0;
	code[0] = start;

	// This seems silly, but it helps to reuse the code
	for (i = 0; i < icand; i++)
		candidates[i] = i;

	populate_candidates(start, candidates, next_candidates,
						icand, &inext_cand, min_hd);
	populate_candidates(start, candidates, next_b_candidates,
						icand, &inext_b_cand, min_iso);

	return find_iso(&code[0], 1, &next_candidates[0], inext_cand,
			&next_b_candidates[0], inext_b_cand, min_hd,
			min_iso, a_len, min_b_len, n, a_len + min_b_len);
}
Beispiel #2
0
gint32 execute_plugin(GimpDrawable* d, const char *nome, param_type *p)
{
//	gint i;
	guchar *img, *org;
	gint x,y,x2,y2,w,h;
//	guchar *work;
	GimpPixelRgn region, rgn_org;
	gint bpp = d->bpp;

	gimp_drawable_mask_bounds(d->drawable_id, &x, &y, &x2, &y2);
	w = x2 - x;
	h = y2 - y;

	img = malloc(w * h * bpp);
	org = malloc(w * h * bpp);
//	work = malloc(d.width * d.height * bpp);

	gimp_pixel_rgn_init(&region, d, x, y, w, h, TRUE, TRUE);
	//este é buffer para gravar a imagem modificada.
	gimp_pixel_rgn_init(&rgn_org, d, x, y, w, h, FALSE, FALSE);
	// Esta é a imagem em si 

	gimp_pixel_rgn_get_rect(&region, img, x, y, w, h);
	gimp_pixel_rgn_get_rect(&rgn_org, org, x, y, w, h);

	switch (*nome) {
		case 'S':
			super_grow(p, org, img, w, h, bpp);
			break;
		case 'G':
			memcpy(img, org, w * h * bpp);
			grow(p, org, img, w, h, bpp);
			break;
		case 'A':
			find_iso(p, org, img, w, h, bpp);
			break;
		default:
			make_height_field(p, org, img, w, h, bpp);
			break;
			
	}

	gimp_pixel_rgn_set_rect(&region, img, x, y, w, h);

	/* finish the process */
	gimp_drawable_flush (d);
	gimp_drawable_merge_shadow (d->drawable_id, TRUE);
	gimp_drawable_update (d->drawable_id, x, y, w, h);
	gimp_displays_flush();
	gimp_drawable_detach(d);

	free(img);
	free(org);

	return GIMP_PDB_SUCCESS;	
}
/* recursive search for pairs of complementary codes */
uint16_t find_iso(uint16_t* code, uint16_t icode, uint16_t* candidates,
		uint16_t icand, uint16_t* b_candidates, uint16_t ib_cand,
		uint8_t min_hd, uint8_t min_iso, uint16_t a_len,
		uint16_t min_b_len, uint8_t n, uint16_t min_len)
{
	//printf("find_iso icode=%d, icand=%d, ib_cand=%d\n", icode, icand, ib_cand);
	uint16_t c;
	uint16_t next_candidates[MAX_CAND];
	uint16_t next_b_candidates[MAX_CAND];
	uint16_t inext_cand;
	uint16_t inext_b_cand;
	uint16_t max_b_len, total_len;
	uint16_t best_len;
	uint16_t longest = 0;

	while (icand) {
		c = *(candidates + --icand);
		*(code + icode++) = c;
		inext_cand = 0;
		inext_b_cand = 0;
		populate_candidates(c, candidates, next_candidates,
							icand, &inext_cand, min_hd);
		populate_candidates(c, b_candidates, next_b_candidates,
							ib_cand, &inext_b_cand, min_iso);

		if (((inext_cand + icode) >= a_len) && (inext_b_cand >= min_b_len)) {
			if (icode == a_len) {
				uint16_t b_code[MAX_CAND];
				best_len =  find_comp(code, icode, &b_code[0], 0,
									  &next_b_candidates[0], inext_b_cand,
									  min_hd, min_b_len, min_len);
				if (best_len >= min_len) {
					longest = best_len;
					min_len = best_len;
					if(find_longest==1)
						min_len++;
				}
			}
			if ((inext_cand) && (icode < a_len)) {
				best_len = find_iso(code, icode, &next_candidates[0],
						inext_cand, &next_b_candidates[0], inext_b_cand,
						min_hd, min_iso, a_len, min_b_len, n, min_len);
				if (best_len >= min_len) {
					longest = best_len;
					min_len = best_len;
					if(find_longest==1)
						min_len++;
				}
			}
		}
		icode--;
	}
	return longest;
}